我们使用AFNetworking 2.0的应用程序遇到了以下问题.当使用AFHTTPRequestOperationManager
's GET方法时,我们遇到了错误NSURLErrorDomain code -1012
.请求使用HTTPS,服务器不需要用户身份验证.请求永远不会到达服务器.
我们已经运行了几个测试,这是第一次产生错误,我们想知道如何产生这个错误,因为它似乎不相关.
AFHTTPRequestOperationManager的设置:
httpOperationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL: [NSURL URLWithString: HTTPS_URL)]]; httpOperationManager.responseSerializer = [AFXMLParserResponseSerializer serializer]; [[AFNetworkActivityIndicatorManager sharedManager] setEnabled: YES];
获得请求
AFHTTPRequestOperation *op =[httpOperationManager GET: [NSString stringWithFormat:SOME_PATH] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { //code to setup NSXMLParser ... } failure: ^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error %@", [error localizedDescription]); }];
reinaldoluck.. 47
我认为您已经解决了问题,但如果您尝试在没有有效证书的服务器中进行身份验证,则必须在对象中设置YES
属性:allowInvalidCertificates
AFHTTPRequestOperationManager
[yourManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"your_username" password:@"your_password"]; [yourManager.securityPolicy setAllowInvalidCertificates:YES];
另外,正如@ a1phanumeric所说,可能需要包含以下行:
[yourManager.securityPolicy setValidatesDomainName:NO];
干杯.
我认为您已经解决了问题,但如果您尝试在没有有效证书的服务器中进行身份验证,则必须在对象中设置YES
属性:allowInvalidCertificates
AFHTTPRequestOperationManager
[yourManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"your_username" password:@"your_password"]; [yourManager.securityPolicy setAllowInvalidCertificates:YES];
另外,正如@ a1phanumeric所说,可能需要包含以下行:
[yourManager.securityPolicy setValidatesDomainName:NO];
干杯.