iOS Project bypass certificate access HTTPS program

Source: Internet
Author: User

If the request is a single webview or request, implement nsurlconnectiondelegate directly in the requested file H and add the following two methods in M:

C code
  1. -(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace * ) Protectionspace {
  2. return [Protectionspace.authenticationmethod isequaltostring:nsurlauthenticationmethodservertrust];
  3. }
  4. -(void) connection: (Nsurlconnection *) connection Didreceiveauthenticationchallenge: ( Nsurlauthenticationchallenge *) Challenge {
  5. if ([Challenge.protectionSpace.authenticationMethod isequaltostring:nsurlauthenticationmethodservertrust])
  6. //if ([trustedhosts containsObject:challenge.protectionSpace.host])
  7. [Challenge.sender usecredential:[nsurlcredential CredentialForTrust:challenge.protectionSpace.serverTrust]
  8. Forauthenticationchallenge:challenge];
  9. [Challenge.sender Continuewithoutcredentialforauthenticationchallenge:challenge];
  10. }
-(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace *) protectionspace {    return [Protectionspace.authenticationmethod isequaltostring: Nsurlauthenticationmethodservertrust];} -(void) connection: (Nsurlconnection *) connection Didreceiveauthenticationchallenge: (Nsurlauthenticationchallenge * ) Challenge {    if ([Challenge.protectionSpace.authenticationMethod isequaltostring: Nsurlauthenticationmethodservertrust])        //if ([trustedhosts containsObject:challenge.protectionSpace.host])            [Challenge.sender usecredential:[nsurlcredential CredentialForTrust:challenge.protectionSpace.serverTrust]                  Forauthenticationchallenge:challenge];      [Challenge.sender Continuewithoutcredentialforauthenticationchallenge:challenge];}

The above method is very uncomfortable is the place of each request to add.

If the project uses the THREE20, directly modify the "TTREQUESTLOADER.M" can be, the file itself has been implemented nsurlconnectiondelegate,

Modified as follows, only change this one place is OK, everywhere is available.

C code
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. -(void) connection: (Nsurlconnection *) connection
  3. Didreceiveauthenticationchallenge: (Nsurlauthenticationchallenge *) challenge{
  4. //Modify
  5. if ([Challenge.protectionSpace.authenticationMethod isequaltostring:nsurlauthenticationmethodservertrust])
  6. [Challenge.sender usecredential:[nsurlcredential CredentialForTrust:challenge.protectionSpace.serverTrust] Forauthenticationchallenge:challenge];
  7. [Challenge.sender Continuewithoutcredentialforauthenticationchallenge:challenge];
  8. Ttdconditionlog (ttdflag_urlrequest, @"RECEIVED AUTH Challenge LOADING%@", _urlpath);
  9. [_queue loader:self Didreceiveauthenticationchallenge:challenge];
  10. }
  11. Add to
  12. -(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace * ) Protectionspace {
  13. return [Protectionspace.authenticationmethod isequaltostring:nsurlauthenticationmethodservertrust];
  14. }
-(void) Connection: (Nsurlconnection *) Connectiondidreceiveauthenticationchallenge: (Nsurlauthenticationchallenge *) challenge{//Modify if ([Challenge.protectionSpace.authenticationMethod isequaltostring: Nsurlauthenticationmethodservertrust]) [Challenge.sender usecredential:[nsurlcredential credentialForTrust:    Challenge.protectionSpace.serverTrust] Forauthenticationchallenge:challenge];        [Challenge.sender Continuewithoutcredentialforauthenticationchallenge:challenge];    Ttdconditionlog (Ttdflag_urlrequest, @ "RECEIVED AUTH challenge LOADING%@", _urlpath); [_queue loader:self didreceiveauthenticationchallenge:challenge];} Add-(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace * ) Protectionspace {return [Protectionspace.authenticationmethod isequaltostring: Nsurlauthenticationmethodservertrust];}

iOS Project bypass certificate access HTTPS program

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.