IOS ASIHTTPRequest encrypt requests with HTTPS protocol

Source: Internet
Author: User

IOS when the terminal requests the server data, in order to ensure the data security, we generally use HTTPS protocol encryption, and for IOS network programming, we typically use an open source framework: ASIHTTPRequest , but if you use a traditional http even if the validation is ignored, the program will report [error-9844] error, the specific error is described below:

" Error domain=asihttprequesterrordomain code=1 "A connection failure occurred" Userinfo=0x6aafa30 { Nsunderlyingerror=0x6a3fd90 "The operation couldn ' t be completed. (Osstatus error-9844.) ", Nslocalizeddescription=a connection failure occurred}"

So how do you solve the problem? Find the following solutions:

Solution Solutions 1

1) [Request Setvalidatessecurecertificate:no];

2) Find "https" in the asihttprequest.m file and add Kcfstreamssllevel object to the Sslproperties dictionary, the reference method on the Internet:

[Sslproperties setobject: (NSString *) (cfstringref*) KCFStreamSocketSecurityLevelSSLv3 Forkey: (nsstring*) kcfstreamssllevel];

However, the Sslproperties dictionary is not a mutable dictionary, so you need to change sslproperties to a mutable dictionary nsmutabledictionary.

Solution Solutions 2

If you need more flexibility to set the SSL security level, you can refer to Cfstringref*sslsecuritylevel as a variable in the property of the ASIHTTPRequest.h file, as follows:

1) Add a statement in the ASIHTTPRequest.h file:

Cfstringref *sslsecuritylevel;

2) Add the Cfstringref attribute to the ASIHTTPRequest.h file:

@property (assign) Cfstringref *sslsecuritylevel;

3) Add the Cfstringref attribute to the ASIHTTPREQUEST.M file:

@synthesize Sslsecuritylevel;

4) Modification of files in ASIHTTPREQUEST.M:

Nsdictionary *sslproperties = [[Nsdictionary alloc]initwithobjectsandkeys:??, change the immutable dictionary to a mutable dictionary (nsmutabledictionary), i.e.:

Nsmutabledictionary *sslproperties = [[Nsmutabledictionary alloc]initwithobjectsandkeys:??

5) Add the code that sets the SSL security level at the end of the 4 edit statement:

Use requested SSL security level

if ([self sslsecuritylevel]! = nil) {

[Sslproperties setobject: (NSString *) [Self Sslsecuritylevel] Forkey: (NSString *) kcfstreamssllevel];

}

6) Make the following settings in the call request:

[Request Setvalidatessecurecertificate:no];

[Request Setsslsecuritylevel: (cfstringref*) kCFStreamSocketSecurityLevelSSLv3];

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.