Nt_ios notes-nsurlconnection How to change HTTP to HTTPS

Source: Internet
Author: User

Always use nsurlconnection Request HTTP interface, now, for security reasons, you intend to use HTTPS.

So how do you change it?

1. No certificate verification PS: That's what we're using.

1.1 Modify HTTP directly for HTTPS;

1.2 Confirmed "Security.framework"

1.3 Modification completed, can be requested directly.

2. Certificate validation Required

The others are the same as 1, except that they need to be added in the following way.

-(void) connection: (Nsurlconnection *) connection Willsendrequestforauthenticationchallenge: (        Nsurlauthenticationchallenge *) challenge{static cfarrayref certs; if (!certs) {nsdata*certdata =[nsdata datawithcontentsoffile:[[nsbundle mainbundle] pathforresource:@ "Srca" of            type:@ "CER"];            Seccertificateref Rootcert =seccertificatecreatewithdata (Kcfallocatordefault,cfbridgingretain (certData));            const void *array[1] = {Rootcert};            Certs = Cfarraycreate (NULL, array, 1, &kcftypearraycallbacks);    Cfrelease (Rootcert);         For completeness, really does not matter} sectrustref trust = [[Challenge Protectionspace] servertrust];        int err;        Sectrustresulttype trustresult = 0;        Err = sectrustsetanchorcertificates (trust, certs);        if (err = = NOERR) {err = Sectrustevaluate (Trust,&trustresult);        } cfrelease (trust); BOOL trusted = (Err = = NOERR) && ((trustResult = = ksectrustresultproceed) | | (Trustresult = = ksectrustresultconfirm) | |        (Trustresult = = ksectrustresultunspecified)); if (trusted) {[Challenge.sender usecredential:[nsurlcredential credentialForTrust:challenge.protectionSpace.se        Rvertrust] Forauthenticationchallenge:challenge];        }else{[Challenge.sender Cancelauthenticationchallenge:challenge]; }}

Nt_ios notes-nsurlconnection How to change HTTP to HTTPS

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.