AppEngine:如何查看 POST 请求中的内容
我向我的 AppEngine 服务器发送 POST 请求。 HttpServletRequest 告诉我:
POST /connexionDeconnexion HTTP/1.1
User-Agent: Java/1.6.0_20
Host: localhost:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
我已经向世界发送了“HelloHelloHelloHelloHello”,根据内容长度,这是正确的。但是,我不知道如何恢复它。 你能解释一下吗?
I send a POST request to my AppEngine server.
The HttpServletRequest says me :
POST /connexionDeconnexion HTTP/1.1
User-Agent: Java/1.6.0_20
Host: localhost:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
I have sent the world "HelloHelloHelloHelloHello", which is correct according to the Content-Length. However, I don't know how to recover it.
Can you explain me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该给出参数名称和值,然后可以从 httpRequest 对象中提取参数。
request.getParameter("paramName");
更新
客户端
另请参阅
You shoudl give param name and value and then you can extract param from httpRequest object.
request.getParameter("paramName");
Update
client side
Also See
正如 Jigar 所说,您可以使用 request.getParameter() 。如果您确实提交表单或将参数指定为 URL 参数 (http://myhost/mypath?myparam=myvalue),则此方法有效。
如果您将数据作为 POST 正文发送,则应该从其正文中读取数据,即通过调用 request.getInputStream() 检索输入流,然后从此流中读取。
As Jigar said you can use
request.getParameter()
. This works if you really submit the form or specify parameter as a URL argument (http://myhost/mypath?myparam=myvalue).If you send your data as a POST body you should read it from its body, i.e. retrieve input stream by calling
request.getInputStream()
and then read from this stream.