This article mainly introduces the relevant information about the parameters of the Http post request. For more information, see
This article mainly introduces the relevant information about the parameters of the Http post request. For more information, see
This article introduces the Http post Request Parameters in PHP. The specific content is as follows:
In WEB development, the information is basically carried out in POST and GET requests and responses. Because of its URL-based intuition, GET is easy to understand and can be concealed by POST requests, while ensuring security, it also brings difficulties for developers to simulate sending. In the next few blog posts, I will explain in detail several methods for PHP POST requests based on my notes and understanding. If any errors occur, please correct them.
HTTP protocol information is an important part of WEB development. Understanding it can help us better understand BS interaction and help us understand WEB development at a lower level. HTTP is a simple, flexible, and convenient communication protocol. Remember that it is a stateless protocol, that is, a non-memory protocol, each interaction is independent.
We can use the "network" Panel of the browser development tool (IE's F12 Firefox FireBug, etc.) to view the HTTP header information.
Generally, HTTP header information is divided into three types: request information, response information, and interaction information (I think it is also a type of request information ).
1. Request Information:
When a website is accessed, the client sends a request message, which does not contain data. Instead, the client simply contacts the server and prompts the server to return the response information.
The format is two parts: Request Line and message header.
A. Request Line: method (Request method) path (request site address) HTTP/version (Protocol/version information)
Common Request methods include GET/POST/HEAD/OPTION.
B. Message Header:
Host (required): Host and port number. The default port number is 80.
Accept: Type of the expected content to be received (image/gif text/html */*)
Accept-Encoding: the compression type to be received (gzip deflat)
Accept-Charset: The expected character set (UTF-8)
Accept-Language (zh-CN)
Cookie: the user's Cookie Information
Connection: Connection Control
User-Agent: client information
......
The following is a typical request header information:
GET index. php HTTP/1.1
Accept: text/html, application/xhtml + xml, application/xml; q = 0.9, image/webp, */*; q = 0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN, zh; q = 0.8
Cache-Control: max-age = 0
Connection: keep-alive
Cookie: SOHUHOMETAB = visit: 2; IPLOC = CN1407; SUV = 1510312046259910
Host:
If-Modified-Since: Sat, 31 Oct 2015 12:45:22 GMT
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36
2. Response Information
Server return data
The response information is divided into three parts: the response body of the Status line Message Header
A. Status line: HTTP/version (Protocol/version information) status code status text (text description of Status Code)
There are five types of status codes:
1XX: indicates a temporary response. The requester must continue the operation.
2XX: indicates that the response is successful, and the server successfully responds to the request.
3XX: Indicates redirection, which requires further operations by the requester.
4XX: indicates a client error and the server cannot respond normally.
5XX: indicates a server error and the server cannot respond normally.
For more information, see HTTP status codes.
B. Message Header:
Server: Server Information
Content-Encoding: data compression format
Content-Length: Data Length
Content-Type: Data Type
Cache-Control: Cache Control
Connection: Connection Control
Date: Date information
Expires: returned data expiration Information
Last-Modified: returns the Last modification time.
Set-Cookie: Set the Cookie information of the client.
......
C. Response body
The returned page data is displayed as HTML documents on the page.
The following are common response messages:
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: close
Content-Encoding: gzip
Content-Length: 6947
Content-Type: text/html; charset = GBK
Date: Sat, 31 Oct 2015 13:30:11 GMT
Expires:-1
Pragma: no-cache
Proxy-Connection: keep-alive
Server: nginx/1.2.5
Set-Cookie: JSESSIONID = yiuug4yejhc1cdbzydoxlcpn; Path =/
3. interaction information
It is the request information that contains the request data. It is common in the registration of uploaded files.
The request body consists of three parts: the request body of the request line message header.
A. It is the same as the request line for Request Information
B. added data about the request body based on the request header.
Content-Type: Content Type of the uploaded information
Content-Length: the Length of the upload information.
......
C. Request body:
That is, the specific data string of the request (name = xxx & passwork = xxx). Of course, for the sake of security, the POST information is sometimes encrypted.
The following are typical request messages:
GET login. php HTTP/1.1
Host: passport.sohu.com
Accept: text/html, application/xhtml + xml, application/xml
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN, zh; q = 0.8
Cache-Control: max-age = 0
Connection: keep-alive
Content-Length: 166
Content-Type: application/x-www-form-urlencoded
Referer:
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36
Form Data
Domain = sohu.com & callback = Hangzhou & appid = 1113 & userid = FDFFDF % 40sohu.com & password = a3f4384c2bc44fa909ffd0ecc5fa8eb9 & persistentcookie = 0
Knowing what the browser sends to the server, it is not difficult to pretend to be a server in other ways.
In the next section, I will introduce how PHP and JS process the most basic URLs. When solving the GET request section, I will also simulate POST request preparation.
If you think this blog is helpful to you, you can recommend or like it. If you have any questions, you can leave a message below for a discussion. Thank you.