请求失败:“AFMultipartFormData”中的错误请求(400)
我正在与目标c的networking工作。 我的参数types是“formData”。 所以我使用“AFMultipartFormData”
这是我的代码
NSLog(@"enter in requestPostFormData"); AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"]; [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [manager.requestSerializer setValue:strAuthorization forHTTPHeaderField:@"Authorization"]; return [manager POST:baseURL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData){ //passing parameter NSMutableData *name = [[NSMutableData alloc]init]; [name appendData:[[NSString stringWithFormat:@"asha"] dataUsingEncoding:NSUTF8StringEncoding]]; formData appendPartWithFormData:name name:@"name"]; }success:^(NSURLSessionDataTask *task, id responseObject) { NSLog(@"Response: %@", responseObject); }failure:^(NSURLSessionDataTask *task, NSError *error) { NSLog(@"Error: %@", error); }];
现在我得到这个错误
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7feb71498f80> { URL: https://test.instamojo.com/v2/gateway/orders/ } { status code: 400, headers { Allow = "GET, POST, HEAD, OPTIONS"; Connection = "keep-alive"; "Content-Encoding" = gzip; "Content-Length" = 113; "Content-Type" = "application/json; charset=utf-8"; Date = "Fri, 20 May 2016 10:49:01 GMT"; Server = nginx; "Strict-Transport-Security" = "max-age=31536000"; Vary = "Cookie, Accept-Encoding"; "X-Content-Type-Options" = nosniff; "X-Frame-Options" = SAMEORIGIN; "X-XSS-Protection" = "1; mode=block"; } }, NSErrorFailingURLKey=https://test.instamojo.com/v2/gateway/orders/, com.alamofire.serialization.response.error.data=<7b0a2020 20202263 75727265 6e637922 3a205b0a 20202020 20202020 22546869 73206669 656c6420 69732072 65717569 7265642e 220a2020 20205d2c 200a2020 20202274 72616e73 61637469 6f6e5f69 64223a20 5b0a2020 20202020 20202254 68697320 6669656c 64206973 20726571 75697265 642e220a 20202020 5d2c200a 20202020 22656d61 696c223a 205b0a20 20202020 20202022 54686973 20666965 6c642069 73207265 71756972 65642e22 0a202020 205d2c20 0a202020 2022616d 6f756e74 223a205b 0a202020 20202020 20225468 69732066 69656c64 20697320 72657175 69726564 2e220a20 2020205d 2c200a20 20202022 70686f6e 65223a20 5b0a2020 20202020 20202254 68697320 6669656c 64206973 20726571 75697265 642e220a 20202020 5d0a7d0a>, NSLocalizedDescription=Request failed: bad request (400)}
据我所知,这个错误是当我的url不正确生成。 我想我是通过错误的方式参数。
请帮助如何解决这个问题。