本文翻译自:How are parameters sent in an HTTP POST request?
In an HTTP GET request, parameters are sent as a query string : 在HTTP GET请求中,参数作为查询字符串发送:
http://example.com/page?parameter=value&also=another
In an HTTP POST request, the parameters are not sent along with the URI. 在HTTP POST请求中,参数不会与URI一起发送。
Where are the values? 价值在哪里? In the request header? 在请求标头中? In the request body? 在请求正文中? What does it look like? 它是什么样子的?
#1楼
参考:https://stackoom.com/question/z3Qg/如何在HTTP-POST请求中发送参数
#2楼
Form values in HTTP POSTs are sent in the request body, in the same format as the querystring. HTTP POST中的表单值以与查询字符串相同的格式在请求正文中发送。
For more information, see the spec . 有关更多信息,请参见规范 。
#3楼
The content is put after the HTTP headers. 内容放在HTTP标头之后。 The format of an HTTP POST is to have the HTTP headers, followed by a blank line, followed by the request body. HTTP POST的格式为具有HTTP标头,后跟空白行,然后是请求正文。 The POST variables are stored as key-value pairs in the body. POST变量作为键值对存储在主体中。
You can see this in the raw content of an HTTP Post, shown below: 您可以在HTTP Post的原始内容中看到这一点,如下所示:
POST /path/script.cgi HTTP/1.0
From: frog@jmarshall.com
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
home=Cosby&favorite+flavor=flies
You can see this using a tool like Fiddler , which you can use to watch the raw HTTP request and response payloads being sent across the wire. 您可以使用Fiddler之类的工具来查看此信息,该工具可用于观察通过网络发送的原始HTTP请求和响应有效负载。
#4楼
You cannot type it directly on the browser URL bar. 您不能直接在浏览器URL栏上键入它。
You can see how POST data is sent on the Internet with Live HTTP Headers for example. 例如,您可以查看如何使用实时HTTP标头在Internet上发送POST数据。 Result will be something like that 结果将是这样的
http://127.0.0.1/pass.php
POST /pass.php HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://127.0.0.1/pass.php
Cookie: passx=87e8af376bc9d9bfec2c7c0193e6af70; PHPSESSID=l9hk7mfh0ppqecg8gialak6gt5
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 30
username=zurfyx&pass=password
Where it says 它说的地方
Content-Length: 30
username=zurfyx&pass=password
will be the post values. 将是职位价值。
#5楼
The values are sent in the request body, in the format that the content type specifies. 值以内容类型指定的格式在请求正文中发送。
Usually the content type is application/x-www-form-urlencoded
, so the request body uses the same format as the query string: 通常,内容类型为application/x-www-form-urlencoded
,因此请求正文使用与查询字符串相同的格式:
parameter=value&also=another
When you use a file upload in the form, you use the multipart/form-data
encoding instead, which has a different format. 当您使用表单上载文件时,将改用multipart/form-data
编码,格式不同。 It's more complicated, but you usually don't need to care what it looks like, so I won't show an example, but it can be good to know that it exists. 它更复杂,但是您通常不需要关心它的外观,因此我不会显示示例,但是知道它的存在可能会很好。
#6楼
The default media type in a POST request is application/x-www-form-urlencoded
. POST请求中的默认媒体类型为application/x-www-form-urlencoded
。 This is a format for encoding key-value pairs. 这是用于编码键值对的格式。 The keys can be duplicate. 密钥可以重复。 Each key-value pair is separated by an &
character, and each key is separated from its value by an =
character. 每个键值对均以&
字符分隔,每个键与其值之间以=
字符分隔。
For example: 例如:
Name: John Smith
Grade: 19
Is encoded as: 编码为:
Name=John+Smith&Grade=19
This is placed in the request body after the HTTP headers. 它放在HTTP标头之后的请求正文中。