无法调用sportsdatallc API获取比赛日程

问题描述 投票:0回答:1

我尝试了很多,但在调用此 API 以使用以下方法获取比赛时间表时出现此错误:

- (IBAction)getButtonPressed:(id)sender 
{
NSString *string = [NSString stringWithFormat:@"https://api.sportsdatallc.org/nba-Trial(t)1/ru/games/2014/reg/schedule.json?api_key=qgdmf6egtuf5guy9pdvk5ydf"];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSLog(@"url is %@",url);
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    // 3
    NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // 4
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
                                                        message:[error localizedDescription]
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
    [alertView show];
}];

// 5
[operation start];
}

出现此错误:

错误域=com.alamofire.error.serialization.response代码=-1011“请求失败:服务器错误(596)”UserInfo=0x7994db10 {com.alamofire.serialization.response.error.response={URL: https://api.sportsdatallc.org/nba-Trial(t)1/ru/games/2014/reg/schedule.json?api_key=qgdmf6egtuf5guy9pdvk5ydf} {状态代码:596,标头{ 连接=“保持活动”; “内容长度”= 30; “内容类型”=“文本/xml”; 日期 =“2015 年 3 月 20 日星期五 08:55:01 GMT”; 服务器=“Mashery代理”; “X-Mashery-错误代码”=“ERR_596_SERVICE_NOT_FOUND”; } }, NSErrorFailingURLKey=https://api.sportsdatallc.org/nba-Trial(t)1/ru/games/2014/reg/schedule.json?api_key=qgdmf6egtuf5guy9pdvk5ydf, NSLocalizedDescription=请求失败:服务器错误 (596), com.alamofire.serialization.response.error.data=<3c68313e 35393620 53657276 69636520 4e6f7420 466f756e 643c2f68 313e>,NSUnderlyingError=0x7994eb90“请求失败:不可接受的内容类型:text/xml”}

我正在使用这个网站API:

http://developer.sportsdatallc.com/docs/NBA_API

该API使用详情:

每日日程
架构
语法:

http(s)://api.sportsdatallc.org/nba-[access_level][version]/schema/schedule-v2.0.xsd?api_key=[your_api_key]

架构示例:

饲料

语法:

http(s)://api.sportsdatallc.org/nba-[access_level][version]/[locale]/games/[year]/[month]/[day]/schedule.xml?api_key=[your_api_key]

参数格式说明

[access_level] = Production (p), Trial (t)

[version] = whole number (sequential, starting with the number 1)

[year] = Year in 4 digit format (YYYY)

[month] = Month in 2 digit format (MM)

[day] = Day of the month in 2 digit format (DD)

[format] = xml, json

可选参数

[locale] = ru (russian), zh (simplified chinese)
ios objective-c web-services
1个回答
0
投票

在-

[AFHTTPRequestOperationManager initWithBaseURL:]
中,您会发现
responseSerializer
属性被设置为
AFJSONResponseSerializer
的实例。 .

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:myURL]; 

要获得所需的功能(将解析后的 XML 模型作为

responseObject
返回给回调),只需将
responseSerializer
属性设置为
AFXMLResponseSerializer

的实例
manager.responseSerializer = [AFXMLResponseSerializer new];

示例代码:

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:myURL];
manager.responseSerializer = [AFXMLResponseSerializer new];
[manager GET:@"http://www.example.com/feed" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Data: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.