NSLocalizedDescription =(200-299)中的预期状态代码,得到400

时间:2012-03-17 22:29:03

标签: objective-c ios json afnetworking

当我尝试发送HTTP请求以获取JSON响应时:

NSURL *url = [NSURL URLWithString:@"http://data.mycitydataset.gov/api/views/INLINE/rows.json?method=index"];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"Success");
} failure:^(NSURLRequest* req,NSHTTPURLResponse *req2, NSError *error,id mex) {
    NSLog(@"%@", [error description]);
}];

[operation start];

我在日志上得到了这个堆栈:

Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x7bb31b0 {NSErrorFailingURLKey=http://data.baltimorecity.gov/api/views/INLINE/rows.json?method=index, NSLocalizedDescription=Expected status code in (200-299), got 400}

我错过了什么吗?

2 个答案:

答案 0 :(得分:3)

HTTP状态代码400表示“错误请求”。您正在尝试访问格式错误的网址,或者您正在访问的网址要查看您未提供的请求中的内容。

答案 1 :(得分:0)

发生此问题是因为在调用Web服务时未与服务器正确通信。如果你不断尝试同样的事情,你没有得到任何新的回应。请在下面休息,你可能会成功。

  • 1)退出并再次登录(高度优先)

  • 2)重新安装应用并再次检查(最后优先级)