Afnetworking Certificate afnetworking Certificate settings

Source: Internet
Author: User
Tags ssl certificate

+ (afsecuritypolicy*) customsecuritypolicy{///import Certificates FirstNSString *cerpath = [[NSBundle mainbundle] Pathforresource:@"Kudou"OfType:@"cer"];//path to the certificateNSData *certdata =[NSData Datawithcontentsoffile:cerpath]; //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 is recommended to be opened. //set to No, mainly used in this case: the client is requesting a subdomain, and the certificate is a different 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; Of course, the rich can register the wildcard 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; //[Nsset Setwithobject:certdata]//@[certdata]Securitypolicy.pinnedcertificates =@[certdata]; returnsecuritypolicy;}

This invokes the---

+ (afhttpsessionmanager *) Getafhttprequestoperationmanager

{

MYLog(@ "1.getAFHTTPRequestOperationManager");

[Self getToken];

afhttpsessionmanager *manager = [afhttpsessionmanager manager];

Manager. Responseserializer = [afjsonresponseserializer serializer];

Manager.requestserializer=[afjsonrequestserializer Serializer];

Manager. Responseserializer. Acceptablecontenttypes = [nsset setwithobjects:@ "Application/json",@ "Text/json" , @ "text/plain", @ "text/javascript",@ "text/html", Nil];

Manager. Requestserializer. timeOutInterval = 60.f;

[Manager Setsecuritypolicy: [self customsecuritypolicy]];

return manager;

}

Afnetworking Certificate afnetworking Certificate settings

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.