AFNetworking 问题:NSErrorFailingURLKey=url,NSLocalizedDescription=请求失败:错误请求 (400)
Posted
技术标签:
【中文标题】AFNetworking 问题:NSErrorFailingURLKey=url,NSLocalizedDescription=请求失败:错误请求 (400)【英文标题】:AFNetworking issue: NSErrorFailingURLKey=url, NSLocalizedDescription=Request failed: bad request (400) 【发布时间】:2015-05-18 09:42:49 【问题描述】:我正在调用 POST 并将嵌套的 JSON 发送到服务器,如下所示:
NSDictionary* jsonDict = @@"user":@@"accountId":@0,@"active":@NO,@"createdBy":@0,@"createdOn":@"", @"emailAddress":@"", @"firstName":@"", @"gender":@0, @"id":@9, @"lastName":@"", @"role":@5,,@"punchInLocation": @"",
@"punchInLatitude": @18.5081214,
@"punchInLangitude": @73.8431377,
@"punchOutLocation": @"",
@"punchOutLatitude":@0,
@"punchOutLagitude": @0,
@"punchInLocationNotFoundReason": @"NetworkProblem",
@"punchOutLocationNotFoundReason": @"",
@"sdate": @"2014-12-10",
@"spunchInTime": @"08:37:44"
;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"<<removed>>" forHTTPHeaderField:@"userToken"];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager POST:@"<<removed>>" parameters:json success:^(AFHTTPRequestOperation *operation, id responseObject)
NSLog(@"JSON: %@", responseObject);
failure:^(AFHTTPRequestOperation *operation, NSError *error)
NSLog(@"Error: %@", error);
];
但我收到如下错误
status code: 400, headers
"Access-Control-Allow-Origin" = "http://onboard.qlc.in";
"Cache-Control" = public;
Connection = close;
"Content-Encoding" = gzip;
"Content-Length" = 393;
"Content-Type" = "text/html;charset=utf-8";
Date = "Mon, 18 May 2015 09:24:50 GMT";
Server = "Apache/2.2.15 (CentOS) DAV/2 mod_jk/1.2.40";
Vary = "Accept-Encoding,User-Agent";
, NSErrorFailingURLKey=url, NSLocalizedDescription=Request failed: bad request (400)
提前致谢
【问题讨论】:
问题解决了吗?? 【参考方案1】:“punchOutLagitude”和“punchInLangitude”有错别字
它们应该分别是“punchOutLatitude”和“punchInLongitude”
【讨论】:
以上是关于AFNetworking 问题:NSErrorFailingURLKey=url,NSLocalizedDescription=请求失败:错误请求 (400)的主要内容,如果未能解决你的问题,请参考以下文章
如何在旧的 AFNetworking 中使用 AFNetworking 2.0+?