Web Service (I) HTTP Basics

Source: Internet
Author: User

I. Basic Definitions of HTTP

Hyper Text Transfer Protocol (HTTP) was designed to provide a method for publishing and receiving HTML pages. Resources requested through HTTP or HTTPS are identified by the Uniform Resource Identifier (URI. Currently, three versions are available: http/0.9, http/1.0, And/http/1.1. Currently, http/1.0 and 1.1 are widely used.

Http/0.9: used to transmit HTML documents only;

Http/1.0: supports multimedia data processing, keep-live (persistent connection), and cache;

Http/1.1: supports more request methods and finer Cache control; persistent connections;

Ii. HTTP request process

The http transaction process is: a request and its corresponding response.

Http request: request

Format

<Method> <request-URL> <version>

<Headers>

<Entity-body>


Http response: response

Format

<Version> <status> <reason-phrase>

<Headers>

<Entity-body>

Method Request Method; actions that you want to execute on the server, such as GET, POST, and HEAD
Request-URL The requested resource. It can be a relative path (relative to the host location) or a complete URL.
Version Protocol version. Format: http/<major>. <minor>
Headers Http header information
Status Status Code
Reason-phrase Cause phrase; easy-to-read numeric status information
Entity-body Subject

A complete request process:

 

Because http is a stateless (stateless) protocol, the identity of each requester cannot be recorded, and the request is closed immediately after the end of each request. Therefore, each request must first go through DNS resolution, three handshakes, and four disconnections. Therefore, the CPU-consuming clock cycle is a waste of resources. There are two methods to provide efficiency:

1. Parallel requests: Initiate multiple requests at the same time and return multiple responses (the first request can only be one resource );

2. persistent connection: requests are continuously opened after three handshakes. The client can continue the request. The fault is that persistent connections will occupy resources;

Disconnection mode: two methods are used to disconnect a device, no matter which one reaches the upper limit.

Timeout: specifies the time limit for a persistent connection after the connection

Maximum number of requested resources: Maximum number of resources allowed for connection

Iii. HTTP Request Method and response status code

Http request methods include GET, HEAD, POST, DELETE, PUT, OPTIONS, TRACE.... The first five methods are commonly used.

GET The server sends a request to obtain a resource.
HEAD Requests a resource, but the server does not need to send the resource but only returns the response header information.
POST Form submission. HTML form submission is supported. The form contains user-filled data. The data is sent to the server. The data is stored on the server to a certain location.
PUT Write documents to the server, such as the publishing system
DELETE Request to delete the resource pointed to by the URL
OPTIONS Method for Detecting requests supported by the server to a resource
TRACE Tracks request resource transmission through firewalls, proxies, or gateways.
CONNECT The HTTP/1.1 protocol is reserved for proxy servers that can change connections to pipelines.
Extension Method LOCK, MKCOL, COPY, MOVE...


There are five status codes in the http response:

1xx: Information Status Code

2xx: Success status code

200: OK

201: created

3xx: redirect status code

301: Moved Permanentl; Use the header "Location: URL" in the Response Message; specify the current Location of the Resource

302: Fonud (temporary redirection); Use the header "Location: URL" in the Response Message; specify the Location of the temporary resource

304: Not Modified (the cache can be used). The client is notified that the resource has Not been changed.

4xx: client error message

403: Forbidden; the request is rejected by the server
404: Not Found; the server cannot find the requested URL
405: Method Not Allowed; you are Not Allowed to use this Method to request the corresponding URL.

5xx: server error message

500: Internal Server Error; Internal Server Error
502: Bad Gateway; the proxy server receives a pseudo response from the superior
503: Service Unavailable; the server cannot provide services at this time, but may be available in the future

Web Service input/output structure:

1. Single-thread I/O structure: a single thread responds to a single request

2. multithreading I/O structure: multiple threads respond to corresponding requests

3. Reusable I/O structure: a single thread responds to multiple requests

4. Reusable multi-threaded I/O structure: multiple threads; a single thread responds to multiple requests

  • 1
  • 2
  • Next Page

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.