Xcode7.0 the above version must be operated: HTTPS HTTP
- Add the Nsapptransportsecurity type dictionary in Info.plist.
- Add Nsallowsarbitraryloads type Boolean under Nsapptransportsecurity with the value set to Yes
HTTP protocol
1. HTTP Protocol
Hypertext Transfer Protocol Hypertext Transfer Protocol. The original purpose of designing HTTP was to provide a way to publish and receive HTML pages.
is a standard for client and server-side requests and responses. The client sends an HTTP request to the specified port on the server (the default port is 80), the server listens for requests sent by the client on the specified port, and, once received, sends back a status line and message to the client (that is, the resource requested by the client). After the client receives the resource (hypertext), it can be displayed after parsing the data through some programs (browsers).
The resource requested through the HTTP/HTTPS protocol is identified by the Uniform Resource Identifier (Uniform Resource Identifiers), which is the URI.
Format: HTTP://IP (address, domain name): Port/path/index.php? parameter list, each parameter in the parameter list is separated by the & symbol, the parameter is key = value
The website address entered in the browser's address bar is called a URL (Uniform Resource Locator, Uniform Resource Locator), which can be interpreted as a house address.
Both can determine the location of the resource to be accessed on the server.
The URL is a subset of the URI.
[Extension notes]
The network architecture of the computer is divided into the following 7 tiers:
-Data is transferred from the bottom up, and each layer follows a different protocol. Where the HTTP protocol, and below the HTTPS protocol, is in the application layer.
-HTTPS: Application layer protocol, hypertext Transfer Protocol over secure Socket layer, is a security-targeted HTTP channel, which can be said to be a secure version of HTTP. An SSL layer is added under HTTP to encrypt the contents of the transfer. The successor of SSL is TLS (protocol that provides data encryption and integrity).
Different from http:
--HTTPS requires a certificate to be applied to the CA, which usually requires a fee. This certificate is used on the server side to prove the service-side purpose type, and the client trusts this host, such as the banking system Web site, only when the certificate is used for its corresponding servers. 12306 Developer Account Https://developer.apple.com
--HTTP is clear text transmission, HTTPS is a secure SSL encryption transmission, identity authentication.
--they are connected in different ways, the default port is not the same, HTTP is a, HTTPS is 443.
-TCP/UDP: Transport Layer Protocol (transmission Control Protocol, transmission protocol) Instant Messenger socket XMPP
[Socket is the encapsulation and application of the TCP/IP protocol, through which the TCP/IP protocol can be used.] ] XMPP
-IP: Network layer Protocol (Internet Protocol, network protocol)
Instant Messaging technology: Socket or XMPP
Total: TCP/IP is the transfer of data to resolve how the data is transmitted over the network, and HTTP is to solve how the data is packaged to make the transmitted data meaningful.
2. HTTP Request/Response
>HTTP Request:
When a client makes a request to the server, it passes a packet nsdata 0101 to the server, which is the request information, including the following:
-Request method, URI, protocol URL:HTTP://IP address or domain name WWW.BAIDU.COM:80 (port)/path? parameter list (username=qidalin&password=123456&id=123) Get Request method
-Requests Header (request header)
-Request Body
For example:
/* Request method/uri/Protocol and protocol version */
get/sample.jsphttp/1.1
/* Request Header */
accept:image/gif.image/jpeg,*/*//Specify what type of content the client receives
ACCEPT-LANGUAGE:ZH-CN//Browser is acceptable
Connection:keep-alive//Whether a persistent connection is required
Host:localhost//Specify the domain name and port number of the requested server
user-agent:mozila/4.0 (compatible; MSIE5.01; Window NT5.0)//contains client information for making the request
Accept-encoding:gzip,deflate//client can support the server return content compression encoding type
......
See other "/HTTP request headers "
/* request body, which can contain query string information submitted by the client */
Type = 123
> HTTP Response
Similar to the request, consists of the following:
-Protocol version/Status code
-Response Header (Response header)
-Response body
For example:
/* protocol version/Status code */
http/1.1 OK
/* Response Header */
Server:tws
Date:tue, 07:22:55 GMT
Content-type:application/json;charset=utf-8
.....
See other "/http response Head "
/* Response Body */
{"Resultmsg": "Comments is lesson than", "data": null, "Issuccess": false}
3. HTTP Request Method
HTTP requests can use a variety of request methods, depending on the HTTP standard. For example: HTTP1.1 supports 7 methods of request: GET, POST, HEAD, OPTIONS, PUT, delete, and Tarce. In Internet applications, the most common method is get and post.
- GET Method
is the default HTTP request method, usually also use get to submit form data, but this way to form data only through simple code, and as part of the URL to the server sent, there is a certain security risks.
For example, http://www.xxx.com/login.jsp?username=xiao&password=12345678
It is easy to identify the submitted content (?) from this request. Later), and this is a concatenation URL string, if the transmission of more content, it will make the URL is very long, and the URL length is limited, the excess of the part will not be sent. 2k
- POST Method
It is used primarily to submit form data to the server, especially for bulk data. In this way, the data is not part of the URL but is passed to the server as standard data.
The Post method overcomes the disadvantage that the information in the Get method is not confidential and the data volume is small. For security reasons, form submissions generally take post.
4. HTTP Status Code /Response code
is a 3-bit numeric code that represents the status of the server HTTP response.
The first number of all status codes represents one of five states.
Common status codes are as follows:
-2 word Head success
OK: Success
-3 Word Header redirection
multiple Choices: redirect
-4-Word Header request error
"Bad Request"
401 Unauthorized: Not authorized
403 Forbidden: No access
404 Not Found: Found
-5, 6-word-Header server error
Internal Server Error: Internal server errors
Basic knowledge of HTTP protocol