HTTPS proxy Access certificate issues under iOS

Source: Internet
Author: User

Under iOS, the HTTPS link needs to be turned on, but if proxy access is used, it will be returned by default with a certificate validation error and no normal access

Usually in the case of domestic visits to foreign Facebook

This is because

HTTPS access, the certificate will be verified once, if the use of agents, the certificate will be considered risky, it will reject the connection

That is, to avoid a man-in-the-middle attack.

Here you can consider the first use of nsurlconnection to create an HTTPS connection, so that the connection to the destination address at the time of authentication ignore the certificate, you can ensure that the subsequent connection and no certificate validation issues

nsstring* strURL = [NSString stringWithFormat: @https://graph.facebook.com/me];nsurlrequest* Requrl =[Nsurlrequest Requestwithurl:[nsurl Urlwithstring:strurl]; Nsurlconnection* conn = [nsurlconnection Connectionwithrequest:requrlDelegate: Self]; [Conn start]; - (void) Connection: (Nsurlconnection *) connection didfailwitherror: (Nserror *) error{NSLog (@"connection Didfailwitherror Result:%@", error);}-(BOOL) Connectionshouldusecredentialstorage: (Nsurlconnection *) connection{returnNO;}- (void) Connection: (Nsurlconnection *) connection Willsendrequestforauthenticationchallenge: ( Nsurlauthenticationchallenge *) challenge{//the first pass is validated, then the validation is canceled    if([challenge previousfailurecount] = =0) {nsurlcredential*credential =[Nsurlcredential CredentialForTrust:challenge.protectionSpace.serverTrust];
[[Challenge Sender] usecredential:credential Forauthenticationchallenge:challenge]; }
Else{[[Challenge Sender] cancelauthenticationchallenge:challenge]; }}//Deprecated authentication delegates.-(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace *) protectionspace{return[Protectionspace.authenticationmethod isequaltostring:nsurlauthenticationmethodservertrust];}- (void) Connection: (Nsurlconnection *) connection Didreceiveauthenticationchallenge: (Nsurlauthenticationchallenge *) challenge{//the first pass is validated, then the validation is canceled if([challenge previousfailurecount] = =0) {nsurlcredential*credential =[Nsurlcredential CredentialForTrust:challenge.protectionSpace.serverTrust];
[[Challenge Sender] usecredential:credential Forauthenticationchallenge:challenge]; }
Else{[[Challenge Sender] cancelauthenticationchallenge:challenge]; }}- (void) Connection: (Nsurlconnection *) connection Didcancelauthenticationchallenge: (Nsurlauthenticationchallenge *) challenge{}- (void) Connection: (Nsurlconnection *) connection didreceiveresponse: (Nsurlresponse *) response{//do the things you need to do}

But this is best to see the latest SDK support is not supported.

HTTPS proxy Access certificate issues under iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.