糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > 如何在HTTP POST请求中发送参数?

如何在HTTP POST请求中发送参数?

时间:2018-08-06 04:45:14

相关推荐

如何在HTTP POST请求中发送参数?

本文翻译自:How are parameters sent in an HTTP POST request?

In an HTTPGETrequest, parameters are sent as aquery string:在HTTPGET请求中,参数作为查询字符串发送:

/page?parameter=value&also=another

In an HTTPPOSTrequest, the parameters are not sent along with the URI.在HTTPPOST请求中,参数不会与URI一起发送。

Where are the values?价值在哪里?In the request header?在请求标头中?In the request body?在请求正文中?What does it look like?它是什么样子的?

#1楼

参考:/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.0From: frog@User-Agent: HTTPTool/1.0Content-Type: application/x-www-form-urlencodedContent-Length: 32home=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.phpPOST /pass.php HTTP/1.1Host: 127.0.0.1User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/0101 Firefox/18.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateDNT: 1Referer: http://127.0.0.1/pass.phpCookie: passx=87e8af376bc9d9bfec2c7c0193e6af70; PHPSESSID=l9hk7mfh0ppqecg8gialak6gt5Connection: keep-aliveContent-Type: application/x-www-form-urlencodedContent-Length: 30username=zurfyx&pass=password

Where it says它说的地方

Content-Length: 30username=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 isapplication/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 themultipart/form-dataencoding 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 isapplication/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 SmithGrade: 19

Is encoded as:编码为:

Name=John+Smith&Grade=19

This is placed in the request body after the HTTP headers.它放在HTTP标头之后的请求正文中。

如果觉得《如何在HTTP POST请求中发送参数?》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。