Knowledge of using HTTPS in iOS

Source: Internet
Author: User

Read the article first, this article is about using afnetworing for HTTPS when things, very good! http://blog.cnbang.net/tech/2416/

Using HTTPS in iOS is primarily the use of nsurlcredential, first look at the necessary official documents:

 nsurlcredential is  an immutable object  representing an authentication credential consisting of authentication information specific to the type of credent Ial and the type of persistent storage to use, if  the URL Loading system supports three types of Credentials:password   -based user credentials, certificate-based user credentials, and certificate- Span style= "color: #000000;" >based server credentials (used when verifying the server's identity).  When you create a credential, you can specify the it should be used  for  a Sin GLE request, persisted temporarily (until your app quits), or persisted permanently (in the keychain). 

Although there are many kinds of credentials, there are only 3 of them for URLs!

So there are 3 initialization methods:

+ Credentialfortrust:+ credentialWithUser:password:persistence:+ credentialwithidentity: Certificates:persistence:

Also, refer to the authentication section in the URL Session Programming Guide:

To attempt to authenticate, the application should create a Nsurlcredential object with authentication information of the Form expected by the server. You can determine the server's authentication method by calling Authenticationmethod on the protection space of the Provid Ed authentication challenge. Some authentication methods supported by Nsurlcredential Are:http Basic Authentication ( Nsurlauthenticationmethodhttpbasic) requires a user name and password. Prompt the user for the necessary information and create a Nsurlcredential object with CredentialWithUser:password:persis Tence:.


HTTP Digest Authentication (nsurlauthenticationmethodhttpdigest), like Basic authentication, requires a user name and pass Word. (The digest is generated automatically.) Prompt the user for the necessary information and create a Nsurlcredential object with CredentialWithUser:password:persis Tence:.


Client certificate Authentication(nsurlauthenticationmethodclientcertificate) requires the system identity and all certificates needed to authenticate wit H the server. Create an Nsurlcredential object with CredentialWithIdentity:certificates:persistence:.


Server Trust Authentication(Nsurlauthenticationmethodservertrust) requires a trust provided by the protection space of the authentication challenge. Create an Nsurlcredential object with Credentialfortrust:. After you ' ve created the Nsurlcredential object:For nsurlsession, pass the object to the authentication challenge ' s sender using the provided completion handler block.For Nsurlconnection and Nsurldownload, pass the object to the authentication Challenge's sender with Usecredential:forauthenticationchallenge:.

Knowledge of using HTTPS in iOS

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.