1 HTTP Basics

Source: Internet
Author: User

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

    1. Establish a TCP connection
    2. Web browser sends request command to Web server
    3. Web browser sends request header information
    4. Web server Answer
    5. Web server sends answer header information
    6. Web server sends data to browser
    7. Web server shuts down TCP connection

An HTTP request consists of four parts:

    1. The method or action of an HTTP request, such as a GET or post plea
    2. The URL of a plea
    3. The request header, which contains some client environment information, authentication, etc.
    4. 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:

    1. Get: Used for information acquisition, using URL to pass parameters, there is a limit on the number of messages sent, generally in 2000 characters
    2. POST: Typically used to modify resources on the server, no limit on the number of messages sent

Second, the HTTP response composition

    1. A number and text-based status code to show whether the request succeeded or failed
    2. The response header, as well as the request header, contains many useful information, such as server type, datetime, content type and length, etc.
    3. 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

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.