0

我在向 .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>}
4

2 回答 2

0

您是否尝试设置 AFNetworking 以允许无效证书?

httpClient.allowsInvalidSSLCertificate = YES;

如果你想使用操作。

AFSecurityPolicy *sec=[[AFSecurityPolicy alloc] init];
[sec setAllowInvalidCertificates:YES];
operation.securityPolicy=sec;
于 2014-11-19T15:37:30.210 回答
0

我认为 AfNetworking for WCF web 服务存在一些问题。最终我可以通过使用标准的 NSURLConnection 类来连接和使用网络服务。尽管我现在面临 PUT 请求的相同问题。

于 2013-09-09T14:45:52.273 回答