以下是test form
假设我需要提交名字x
和姓氏y
。因此,我只需输入以下get
url
请求
http://www.w3schools.com/tags/demo_form_method.asp?fname=x&lname=y
现在,如果我更改method="post"
,则上述方法无效。如何以编程方式提交post
请求,然后print
将结果页面提交给console
?
我尝试使用很多方法。例如
PostMethod post = new PostMethod("http://www.w3schools.com/tags/demo_form_method.asp");
NameValuePair[] data = {
new NameValuePair("fname", "x"),
new NameValuePair("lname", "y")
};
post.setRequestBody(data);
...
InputStream in = post.getResponseBodyAsStream();
答案 0 :(得分:1)
我可以看到你的测试表格不支持"发布"方法。我粘贴了
下面的表单摘要 <form action="demo_form_method.asp" **method="get"** target="_blank">
互联网上有很多关于表单如何为post方法工作的帮助以及如何发送&#34; post&#34;请求通过java。
以下随机参考文献:
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1
http://alien.dowling.edu/~vassil/tutorials/javapost.php
HTH