我正在尝试发出一个 put 请求,以便能够更改我传入的参数,但出现 400 错误。
Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299),
got 400" UserInfo=0x8a7d7d0 {NSLocalizedRecoverySuggestion={"messages":{"error":
[{"code":400,"message":"Server can not understand Content-Type HTTP header media type
\"application\/x-www-form-urlencoded\""}]}},
AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest
http://test.example.com/api/rest/customers/841>,
NSErrorFailingURLKey=http://test.example.com/api/rest/customers/841,
NSLocalizedDescription=Expected status code in (200-299), got 400,
AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8a7e1e0>}
这是我的请求代码。
ExampleHTTPClient *sharedClient = [ExampleHTTPClient sharedClient];
NSDictionary *parameter = @{@"email":@"example@gmail.com",@"firstname":@"Bob", @"lastname":@"Jones"};
[sharedClient setDefaultHeader:@"Content-Type" value:@"application/json"];
[sharedClient putPath:@"/api/rest/customers/841" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
我是使用 Web 服务的新手,所以我的问题是了解发生了什么。
任何帮助或想法表示赞赏,谢谢。