How to use NSURLConnection to connect with SSL for an untrusted cert?

后端 未结 13 1580
盖世英雄少女心
盖世英雄少女心 2020-11-22 01:29

I have the following simple code to connect to a SSL webpage

NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[ NSURLConnection send         


        
13条回答
  •  借酒劲吻你
    2020-11-22 01:40

    With AFNetworking I have successfully consumed https webservice with below code,

    NSString *aStrServerUrl = WS_URL;
    
    // Initialize AFHTTPRequestOperationManager...
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    manager.securityPolicy.allowInvalidCertificates = YES; 
    [manager POST:aStrServerUrl parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        successBlock(operation, responseObject);
    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        errorBlock(operation, error);
    }];
    

提交回复
热议问题