错误域= com.alamofire.error.serialization.response代码= -1011“请求失败:错误的请求(400)
我正在使用AFnetworking库在服务器上发布数据。
以下是我的代码发布数据在服务器上。
- (void) callLoginAPI:(NSDictionary *)dictProfile{ // 1 NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:[dictProfile valueForKey:@"name"], @"username", [dictProfile valueForKey:@"first_name"],@"first_name", [dictProfile valueForKey:@"last_name"],@"last_name", [dictProfile valueForKey:@"email"],@"email", [dictProfile valueForKey:@"birthday"],@"dob", [dictProfile valueForKey:@"gender"],@"gender", [[dictProfile valueForKey:@"location"] valueForKey:@"name"],@"location", [dictProfile valueForKey:@"timezone"],@"timezone", @"",@"language", [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large",[dictProfile valueForKey:@"id"]],@"profile_pic_url", @"",@"cover_pic_url",nil]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager POST:@"http://10.1.81.35:8000/api/login/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; }
作为回应,我得到了以下错误
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo=0x7c87b6f0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7cc220e0> { URL: http://10.1.81.35:8000/api/login/ } { status code: 400, headers { Allow = "POST, OPTIONS"; "Content-Type" = "application/json"; Date = "Tue, 07 Oct 2014 10:45:08 GMT"; Server = "WSGIServer/0.1 Python/2.7.6"; Vary = "Accept, Cookie"; "X-Frame-Options" = SAMEORIGIN; } }, NSErrorFailingURLKey=http://10.1.81.35:8000/api/login/, NSLocalizedDescription=Request failed: bad request (400), com.alamofire.serialization.response.error.data=<7b226465 7461696c 223a2022 4a534f4e 20706172 73652065 72726f72 202d204e 6f204a53 4f4e206f 626a6563 7420636f 756c6420 62652064 65636f64 6564227d>}
我无法理解为什么我会遇到这样的错误。 我的代码中缺less什么?
这个错误说明了一切:你从服务器得到了一个400响应 ,这意味着你发送的内容不是格式正确,或者服务器无法理解。
请添加此行到您的代码,我希望它可以帮助你。
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
我遇到了同样的问题。 在我的情况下,它唯一的上传图像与较大的尺寸。 我们的服务器限制了max.upload大小。 我调整了图像大小并上传,问题没有了。
您可以使用以下命令调整图像大小:
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize; { UIGraphicsBeginImageContext( newSize ); [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }
- 如果用户使用Firebase身份validation和Swiftvalidation了他们的电子邮件,我该如何redirect到我的应用程序?
- 当单元格被选中时,button的背景颜色会改变,然后录制
- 在UICollectionView的每个边缘放置一个边距
- AVFoundation – 反转AVAsset并输出video文件
- 如何在iOS上列出可用的audio输出path
- 最好的“初始化”方法来设置iOS 7的variables值?
- 当应用程序从后台移除或重启设备时,使用NSURLSession恢复任务
- 我怎样才能使用NSDateFormatter获得string“昨天”?
- iPhone / iOS:如何获取我的应用程序本地化的所有语言的本地化string列表?