Tagged with:. com elf res date URI wildcard SETW encapsulated color
Based on AFN3.0
1. Save the. cer file file provided in the background to the local
2. Assign a value to the Afsecuritypolicy property of AFN in the Encapsulated Network Request tool class
-(Afsecuritypolicy *) customsecuritypolicy{//first import the certificate, in this add the certificate, the general situation applies to the individual authentication//path to the certificateNSString *cerpath = [[NSBundle mainbundle] Pathforresource:@"app"OfType:@"cer"]; NSData*cerdata =[NSData Datawithcontentsoffile:cerpath]; if(Cerdata = =Nil) { returnNil; } Nsset*setdata =[Nsset Setwithobject:cerdata]; //afsslpinningmodecertificate Using certificate validation modeAfsecuritypolicy *securitypolicy =[Afsecuritypolicy policywithpinningmode:afsslpinningmodecertificate]; //allowinvalidcertificates whether to allow invalid certificates (that is, self-built certificates), default to No//If you need to validate your self-built certificate, you need to set it to YesSecuritypolicy.allowinvalidcertificates =YES; //Validatesdomainname If you need to verify the domain name, the default is yes; //if the domain name of the certificate does not match the domain name you requested, you need to set the entry to no, and if it is set to No, the server can also establish a connection by using a certificate issued by another trusted authority, which is very dangerous and recommended to open. //set to No, mainly used in this case: the client requests the thing subdomain, and the certificate is another domain name. Because the domain name on the SSL certificate is independent, if the domain name registered on the certificate is www.google.com, then mail.google.com cannot be verified, and of course the rich can register the wildcard domain name *.google.com, but this is still relatively expensive. //if set to No, it is recommended that you add the check logic for the corresponding domain name. Securitypolicy.validatesdomainname =NO; [SecurityPolicy Setpinnedcertificates:setdata]; returnsecuritypolicy;}
3. Set when the network request tool is initialized
-(ID) Initwithbaseurl: (Nsurl *) URL { = [Super Initwithbaseurl:url]; if (! Self ) { return nil; } [Self setsecuritypolicy:[self customsecuritypolicy]]; return Self ;}
Self-signed configuration HTTPS