HTTP basic Content
HTTP is a rule for computers to communicate over a network.
is a stateless protocol (does not establish a persistent connection, no memory)
One, the HTTP request process
- Establish a TCP connection
- Web browser sends request command to Web server
- Web browser sends request header information
- Web server Answer
- Web server sends answer header information
- Web server sends data to browser
- Web server shuts down TCP connection
An HTTP request consists of four parts:
- The method or action of an HTTP request, such as a GET or post plea
- The URL of a plea
- The request header, which contains some client environment information, authentication, etc.
- The request body, which is the request body, can contain the query string information submitted by the Customer, form information, etc.
There are two types of request methods:
- Get: Used for information acquisition, using URL to pass parameters, there is a limit on the number of messages sent, generally in 2000 characters
- POST: Typically used to modify resources on the server, no limit on the number of messages sent
Second, the HTTP response composition
- A number and text-based status code to show whether the request succeeded or failed
- The response header, as well as the request header, contains many useful information, such as server type, datetime, content type and length, etc.
- Response body, which is the response body
The HTTP status code consists of 3 digits, with the first number defining the type of the status code
1XX: Information class, indicating receipt of Web browser request, is being further processed
2XX: Successful, indicates that the user request is received correctly, understood and processed for example: OK
3XX: Redirect to indicate that the request was unsuccessful and the customer must take further action
4XX: Client error, indicating that the client submitted a request with an error, for example: 404 Not FOUND, that the document being referenced in the request does not exist.
5XX: Server error, indicating that the server could not complete processing the request: for example: 500
Third, send the request through the XMLHttpRequest object
Open (Method,url,async)//method, address, request synchronous/Asynchronous Send (String) request.open ("POST", "create.php", ture); Request.setrequestheader ("Content-type", "application/x-www-form-urlencoded");//Set Header information Request.send ("Name= Xiaoming & sex= male ");
XMLHttpRequest Get a response
- ResponseText: Getting response data in string form
- Responsexml: Obtaining response data in XML form
- Status and StatusText: Returns the HTTP status code in numeric and textual form
- Getallresponseheader (): Gets all the response headers
- getResponseHeader (): The value of a field in a query response
ReadyState Property
- 0: Request uninitialized, Open has not been called
- 1: The server is connected, open has been called
- 2: The request has been received, that is to receive the header information
- 3: The request is processed, that is, the response body is received
- 4: The request is complete and the response is ready, that is, the response is complete
1 HTTP Basics