我是AFNetworking
框架的新手。我尝试向服务器发送 JSON 请求以获取 JSON 响应,所以我尝试了这样的操作:
NSURL *url = [NSURL URLWithString:@"http://data.mycity.gov/api/views/INLINE/rows.json?method=index"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:[NSString stringWithFormat:@"application/json"] forHTTPHeaderField:@"Content-Type"];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Success");
} failure:^(NSURLRequest* req,NSHTTPURLResponse *req2, NSError *error,id mex) {
NSLog(@"Failed");
NSLog(@"%@",[error description]);
}];
[operation start];
所以我总是发现自己进入了失败块,并带有以下错误描述:
Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x7b58030 {NSErrorFailingURLKey=http://data.mycity.gov/api/views/INLINE/rows.json?method=index, NSLocalizedDescription=Expected status code in (200-299), got 400}
有任何想法吗?我错过了什么吗?