我在向 .net webservice 方法发出 POST 请求时遇到问题。我已经提出了很多帖子请求,但我似乎没有得到我在这里面临的问题在 Rest 客户端的帮助下成功发出请求但它总是给我一个 400 错误我正在使用 AFNetworking 发布帖子请求如果有问题请在下面找到代码
NSURL *url=[NSURL URLWithString:@"http://WebService.svc"];
NSMutableDictionary *params=[NSMutableDictionary dictionary];
[params setValue:@"cabbage123" forKey:@""];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient postPath:[NSString stringWithFormat:@"Users/%@",userId] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
我收到一个带有此错误的 html 响应
AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://WebService.svc/Users/userid>, NSErrorFailingURLKey=http://WebService.svc/Users/userid, NSLocalizedDescription=Expected status code in (200-299), got 400, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7ba6df0>}