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