AFNetworking问题:NSErrorFailingURLKey = url,NSLocalizedDescription =请求失败:错误请求(400)

时间:2015-05-18 09:42:49

标签: ios json afnetworking-2

我正在调用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 个答案:

答案 0 :(得分:1)

&#34; punchOutLagitude&#34;和&#34; punchInLangitude&#34;他们有一个错字

他们应该是&#34; punchOutLatitude&#34;和&#34; punchInLongitude&#34;分别