我正在尝试从java的POST中读取数据。我有registrationForm.html格式的表单:
<form action="registratrationResult.html" method="post">
Mail:<br>
<input type="text" name="mail">
<br>
Password:<br>
<input type="password" name="password">
<input type="submit">
</form>我想在不使用servlet的情况下在java中阅读本文。我从browser上阅读了所有内容,并获得了它:
>POST /registratrationResult.html HTTP/1.1
>Host: localhost:8080
>Connection: keep-alive
>Content-Length: 29
>Cache-Control: max-age=0
>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
>Origin: http://localhost:8080
>Upgrade-Insecure-Requests: 1
>User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
>Content-Type: application/x-www-form-urlencoded
>Referer: http://localhost:8080/registrationForm.html
>Accept-Encoding: gzip, deflate
>Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4我读到应该有这样的东西:
parameter=value&also=another如何获得它?当我改变输入数据时,Content-Length正在改变。
发布于 2015-12-20 04:07:06
正如您所说,实际的POST数据存储为键-值对,但它们放在请求正文中,而不是头中。
使用cURL的示例:
$ curl --data "fname=stackoverflow&lname=user" --trace - http://www.w3schools.com/tags/demo_form_method_post.asp注意输出中的send data区域:
=> Send data, 30 bytes (0x1e)
0000: 66 6e 61 6d 65 3d 73 74 61 63 6b 6f 76 65 72 66 fname=stackoverf
0010: 6c 6f 77 26 6c 6e 61 6d 65 3d 75 73 65 72 low&lname=user
== Info: upload completely sent off: 30 out of 30 bytesPost请求通常与send标头中提到的application/x-www-form-urlencoded内容类型一起发送。
https://stackoverflow.com/questions/34373163
复制相似问题