02-http request and Response full solution

Source: Internet
Author: User

What is an agreement
A criterion for constraining both parties ' norms

What is the HTTP protocol
HTTP, Hypertext Transfer Protocol (hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet.
All www files are subject to this standard.
HTTP was originally designed to provide a way to publish and receive HTML pages
Rules for binding requests and responses

HTTP components
Request
Response
Both the request and the response are paired.

  

How requests are sent
1. Via the browser's address bar
2. Use form form in HTML
3. Via the A linked href
4.SRC Properties

A complete request includes: Request line, request header, request body

Request Line
Request Method
POST
GET
the requested resource
/myxq/login.html?username=myxq&pwd=1234
Protocol version
http/1.0, send a request, create a connection, get a Web resource, disconnect the connection
http/1.1, sends a request, creates a connection, obtains multiple Web resources, and remains connected.
Request Header
the request header is some information that the client sends to the server side
using key-value pairs to represent Key:value
Common Request Headers
Referer: The browser notifies the server where the current request is coming from. If it is direct access, there will be no such header. Commonly used: Anti-theft chain    
if-modified-since: The browser notifies the server of the last change time of the local cache.     
Cookie: Cookie information used to store the browser cache.     
user-agent: Browser notification server, client browser and operating system related information    
Connection: Keep the connection state. Keep-alive connection, close is closed    
Host : The requested server host name    
content-length: The length of the request body    
content-type: If it is a POST request, there will be this header,    

    
Accept :
The MIME types that the browser can support.    A description of the file type
text/html, HTML file
Text/css,css file
Text/javascript,js file
image/*, all picture files
accept-encoding : Browser notification server, data compression format supported by the browser. such as: gzip compression "
accept-language : Browser notification server, browser-supported language
automatically sends the client's information to the server


Request Body
When the request mode is post, the request realizes the requested parameter
If the request method is get, then the request parameter will not appear in the request body, will be stitched behind the URL address

A complete response includes: Response line, response header, response body

Response Line
HTTP protocol
Status Code
200: Request succeeded
302: Request Redirection
304: The request resource has not changed to access the local cache.
404: The request resource does not exist. This is usually a user path write error, or the server resource has been deleted.
500: Server internal error. Usually the program throws an exception.
Other status Codes
Success
OK
201 Created
202 Reception
203 Non-certified information
204 No content
205 Resetting Content
206 part of the content
redirect
300 multi-channel selection
301 Permanent Transfer
302 Temporary Transfer
303 See other
304 unmodified (not Modified)
305 using proxies
Client Side Error
400 Error requests (Bad Request)
401 not certified
402 fee Required
403 Prohibition (Forbidden)
404 Not Found (not Found)
405 method does not allow
406 Not accepted
407 requires agent authentication
408 Request timed out
409 Conflicts
410 Failure
411 Required Length
412 pieces failed
413 Request Entity too large
414 Request URI too long
415 Media type not supported
Server Error
500 Server Internal Error
501 Not implemented (not implemented)
502 Gateway Failure
504 Gateway Timeout
Response Header
Server-side returns information to the client in the form of a key-value pair
Common Request Headers
Location : Specifies the path of the response and needs to be used in conjunction with status Code 302 to complete the jump  
content-type: Type of response Body (MIME type)  
content-disposition: parsing the body via browser download mode  
Set-cookie: server writes cookies to browser  
content-encoding: compression format used by the server  
content-length: length of response body  
Refresh : timed flush  
Server : servers name, default value: apache-coyote/1.1. Can be modified through the Conf/server.xml configuration  
last-modified: Server notifies browser, last modified time of file  
automatically pass server-side information to the client
Response Body
The response body is the page body that the server writes back to the client
the browser loads the body into memory
then parse render display page content

  

8 Types of requests
1.OPTIONS
returns the HTTP request method that the server supports for a specific resource, or a request to send a ' * ' to the Web server to test the server's functionality
2.HEAD
requests the specified page information and returns the header information
3.GET
requests the specified page information and returns the entity principal
4.POST
submit data to a specified resource for processing requests
5.PUT
upload the latest content to the specified resource location
6.DELETE
requesting the server to delete the resource identified by Request-url
7.TRACE
Echo the request received by the server, primarily for testing or diagnostics
8.CONNECT
The http/1.1 protocol is reserved for proxy servers that can change connections to pipelines.


Common two ways to request differences
GET
get  method send parameters to page request
address and parameter information in the middle with the? Character Delimited
http://www.it666.com/hello?key1=value1&key2=value2
query string is displayed in the URL of the address bar and is not secure, do not submit sensitive data using GET requests
GET Method has a size limit: Only 1024 characters can be in the request string
GET request can be cached
Get request is saved in browser's browsing history
can bookmark
encoding type is application/x-www-form-urlencoded

Click Refresh, no response
GET request primarily for data


  POST
POST method Send parameters to page request
When using the Post method, the query string exists separately in the post message and is sent to the server along with the HTTP request
The encoding type is: application/x-www-form-urlencoded or Multipart/form-data. Please use multipart encoding for binary data
No historical records
There is no limit to the parameter type, either a string or a binary stream
The data is not displayed in the address bar and is not cached or saved in the browsing record, so it is safer to look at the post plea than GET request

But it's not the safest way. If you need to transfer sensitive data, use encrypted mode to transfer
Query string does not appear in the address bar
The post transmits a large amount of data, which can reach 2 m, and the Get method can only pass approximately 1024 bytes due to the URL length limit.
Post is to transfer data to the server segment, get is to get the data from the server segment

02-http request and Response full solution

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.