allow invalid certificates with AFNetworking

前端 未结 2 1786
逝去的感伤
逝去的感伤 2021-02-14 22:48

I have been using following code

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
operation.allowsInvalidSSLCertifica         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-14 23:31

    I solved this problem by adding following code before [operation start];

    AFSecurityPolicy *sec=[[AFSecurityPolicy alloc] init];
    [sec setAllowInvalidCertificates:YES];
    operation.securityPolicy=sec;
    

    This happened because AFHTTPRequestOperationManager is not connected to AFHTTPRequestOperation. So setting manager's security certificate can not do magic at requestOperation. So have to initialize and assign one to AFHTTPRequestOperation.

    Hope this help somebody :)

提交回复
热议问题