iOS Network Chapter 2-HTTP Protocol communication Rules

Source: Internet
Author: User

The Hypertext Transfer Protocol (Http-hypertext Transfer Protocol) defines the transport rules for communication between the client and the server. Currently the latest version is 1.1,http is an application-layer protocol, consisting of requests and responses, and is a standard client server model.

First, Features:1, support client/server mode. Support Basic authentication and security certification. 2, simple and fast: When a customer requests a service from the server, it simply transmits the request method and path. The request method commonly has, POST. Each method specifies a different type of contact between the customer and the server. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is fast. 3, Flexible: HTTP allows the transfer of any type of data objects. The type being transmitted is marked by Content-type. 4, HTTP 0.9, and 1.0 use a non-persistent connection: Restricts each connection to only one request, the server finishes processing the customer's request, and receives the customer's response, which disconnects the connection. In this way, the transmission time can be saved. HTTP 1.1 uses persistent connections: You do not have to create a new connection for each Web object, and one connection can transfer multiple objects. 5. No status: HTTP protocol is stateless. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. Second, the URLThe full name of the URL is uniform Resource Locator (Uniform Resource Locator), which, through a URL, can find only one resource on the Internet. Basic format of URL = protocol://host address (domain name)/path for example, the URL of the Baidu image is: Http://image.baidu.com/channel/star protocol: Different protocols represent different ways of finding resources, In addition to the HTTP protocol described in this post, there is a file (local file protocol) FTP (shared host File protocol) and other hosts: the host IP address of the resource or the domain name path: The location of the resource in the host Third, the communication processRequest: Client requests resource response to server: Server returns client response resource1. Request1.1 Request InformationRequest Line: Contains the request method, the request resource path, the HTTP protocol version Example Get/images/logo.gif http/1.1, represents a GET request, from the/images directory request logo.gif This file, the protocol version is 1.1. Request Header: Contains a description of the client host://the server host address that the client wants to access user-agent://client's software environment accept://the type of data the client can accept accept-language://the client's language ring ACCEPT_ENCODING://client supported data compression format request body (optional message body) the specific data sent by the client to the server, in the http/1.1 protocol, is optional in all request methods except post. 1.2 Request method The http/1.1 protocol defines eight ways to indicate the different ways in which a resource is requested: OPTIONS-Returns the HTTP request methods that the server supports for a specific resource. You can also test the functionality of your server with a request to send a ' * ' to the Web server. HEAD-Ask the server for a response that is consistent with the GET request, except that the response body will not be returned. This method allows you to obtain meta information contained in the response message header without having to transmit the entire response content. GET-Make a request to a specific resource. POST-Submits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is included in the request body. A POST request may result in the creation of new resources and/or modification of existing resources. PUT-Uploads its latest content to the specified resource location. DELETE-The requesting server deletes the resource identified by Request-uri. TRACE-echo the requests received by the server, primarily for testing or diagnostics. CONNECT-The http/1.1 protocol is reserved for proxy servers that can change connections to pipelines. PATCH-Used to apply a local modification to a resource. Basically just understand that get, POST, head requests are sufficient to meet all of our needs in iOS development, other methods are basically not used and can not let you achieve, such as delete and put is to the people's server data operation, you certainly do not have this permission.2. Response2.1 Response Information

Status line: The client sends a request to the server, and the server responds with a status line, including the HTTP protocol version, status code, status English name

http/1.1 OK

Common status codes are 200 400 404 500 etc.

OK: The request was successful and the desired response header or data body will be returned with this response.

Request: Semantic or Parameters error, cannot be understood by the server

404 Not Found: The request failed and the requested resource was not found on the server.

Internal Server Error: The server encountered an unexpected condition that prevented it from completing the processing of the request.

Response header: Contains a description of the server, description of the response data server://server type content-type:image/png//Return data type content-lenght:1024//Return data length date://return date ring Body: The specific content that the server returns to the client.

iOS Network Chapter 2-HTTP Protocol communication Rules

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.