gpt4 book ai didi

afnetworking - AFNetworking 2.0-意外的NSURLErrorDomain错误-1012

转载 作者:行者123 更新时间:2023-12-03 11:47:12 31 4
gpt4 key购买 nike

使用AFNetworking 2.0的应用程序遇到以下问题。
使用AFHTTPRequestOperationManager的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]);
}];

最佳答案

我认为您已经解决了问题,但是如果您尝试在没有有效证书的服务器中进行身份验证,则必须在YES对象中为属性allowInvalidCertificates设置AFHTTPRequestOperationManager:

[yourManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"your_username" password:@"your_password"];
[yourManager.securityPolicy setAllowInvalidCertificates:YES];

另外,正如@ a1phanumeric所说,可能需要包括以下行:
[yourManager.securityPolicy setValidatesDomainName:NO];

干杯。

关于afnetworking - AFNetworking 2.0-意外的NSURLErrorDomain错误-1012,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22333020/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com