AFNetworking Post请求无效

时间:2013-09-04 09:24:22

标签: ios .net web-services afnetworking

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

2 个答案:

答案 0 :(得分:0)

我认为AfNetworking对于WCF网络服务存在一些问题。 最终,我可以使用标准的NSURLConnection类连接和使用Web服务。虽然我现在面临着PUT请求的同样问题。

答案 1 :(得分:0)

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

httpClient.allowsInvalidSSLCertificate = YES;

如果您想使用操作。

AFSecurityPolicy *sec=[[AFSecurityPolicy alloc] init];
[sec setAllowInvalidCertificates:YES];
operation.securityPolicy=sec;