报错原因是请求的url 不需要验证域名和请求类型格式
所以修改AFNetworking 请求方式
NSString *url = @"https:xxxxxxxx.txt";
url是txt格式 ,添加text/plain 解决
session.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"text/plain", nil];
以下是正确请求方式
NSString *url = @"https:xxxxxxxx.txt";
AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
// 不用验证域名 没写的话 Error Domain=NSURLErrorDomain Code=-999
AFSecurityPolicy *secur = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[secur setValidatesDomainName:NO];
session.securityPolicy = secur;
session.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"text/plain", nil];
[session.securityPolicy setAllowInvalidCertificates:YES];
[session GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *urlString = responseObject[@"iosURL"];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
} ];
网友评论