美文网首页初见
AF请求报Error Domain=NSURLErrorDoma

AF请求报Error Domain=NSURLErrorDoma

作者: Queen_BJ | 来源:发表于2020-06-19 16:36 被阅读0次

    报错原因是请求的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) {
    
        } ];
    

    相关文章

      网友评论

        本文标题:AF请求报Error Domain=NSURLErrorDoma

        本文链接:https://www.haomeiwen.com/subject/oqfbxktx.html