The ios project bypasses the certificate to access the https program, and the ios project bypasses the certificate https

Source: Internet
Author: User

The ios project bypasses the certificate to access the https program, and the ios project bypasses the certificate https

For a single webview or request, directly implement NSURLConnectionDelegate in the file h of the request, and add the following two methods in m to implement the following:

 

 

C code
  • -(BOOL) connection :( NSURLConnection *) connection canAuthenticateAgainstProtectionSpace :( NSURLProtectionSpace *) protectionSpace {
  • Return [protectionSpace. authenticationMethod isinclutostring: NSURLAuthenticationMethodServerTrust];
  • }
  • -(Void) connection :( NSURLConnection *) connection didReceiveAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {
  • If ([challenge. protectionSpace. authenticationMethod isinclutostring: NSURLAuthenticationMethodServerTrust])
  • // If ([trustedHosts containsObject: challenge. protectionSpace. host])
  • [Challenge. sender useCredential: [NSURLCredential credentialForTrust: challenge. protectionSpace. serverTrust]
  • ForAuthenticationChallenge: challenge];
  • [Challenge. sender continueWithoutCredentialForAuthenticationChallenge: challenge];
  • }
  • - (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 uncomfortable because each request must be added.

     

    If three20 is used in the project, you can directly modify "TTRequestLoader. m". The file itself has implemented NSURLConnectionDelegate,

     

    The modification is as follows. You only need to change this location and it is available everywhere.

     

     

    C code
  • //////////////////////////////////////// //////////////////////////////////////// ///////////////////
  • -(Void) connection :( NSURLConnection *) connection
  • DidReceiveAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {
  • // Modify
  • If ([challenge. protectionSpace. authenticationMethod isinclutostring: 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 isinclutostring: NSURLAuthenticationMethodServerTrust];
  • }
  • //////////////////////////////////////// //////////////////////////////////////// /// //-(Void) connection :( NSURLConnection *) connectiondidReceiveAuthenticationChallenge :( NSURLAuthenticationChallenge *) challenge {// modify if ([challenge. protectionSpace. authenticationMethod isinclutostring: NSURLAuthenticationMethodServerTrust]) [challenge. sender useCredential: [NSURLCredential credentialForTrust: challenge. protectionSpace. serverTrust] forAuthenticationChallenge: challenge]; [challenge. sender handler: challenge]; TTDCONDITIONLOG (TTDFLAG_URLREQUEST, @ "received auth challenge loading % @", _ urlPath); [_ queue loader: self handler: challenge];} // Add-(BOOL) connection :( NSURLConnection *) connection canAuthenticateAgainstProtectionSpace :( NSURLProtectionSpace *) protectionSpace {return [protectionSpace. authenticationMethod isinclutostring: NSURLAuthenticationMethodServerTrust];}

     


    Why do I ignore certificates for ios https?

    [Security and permissions] How does ASIHTTPRequest ignore certificates and request https?
    The problem is as follows.
    The procedure is as follows:
    1. Configure the https website on the server and use the custom certificate.
    2. Use the ASIHTTPRequest framework on the ios Client

    Www.devdiv.com/..170776

    XP disables http webpage access but allows https access. Can this problem be achieved without third-party software?

    Built-in firewall custom rules
     

    Related Article

    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.