作者trevor2005 (....)
看板java
标题[JSP ] httpclient模拟submit问题
时间Fri Nov 30 21:52:18 2007
各位站内高手们麻烦解答小弟疑惑。
小弟想利用httpclient做一个模拟submit的动作
目前我有一个html档案,程式码为:
<body>
<form action="return.jsp" method="POST">
User name:<input type=text name=NAME value="" size=8 maxlength=8><br>
Password: <input type=text name=PASS value="" size=8 maxlength=8><br>
<input name="submit" type=submit value="submit">
</form>
</body>
return.jsp程式码为:
<%
String name = request.getParameter("NAME");
String pass = request.getParameter("PASS");
out.println("HiHi~ " + name + ". Your password : " + pass);
%>
而又有一个想模拟submit的程式,程式码为:
public class SimulateSubmitExample {
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("
http://127.0.0.1:7070/httpclienttest/body/");
NameValuePair[] data = {
new NameValuePair("NAME", "joe"),
new NameValuePair("PASS", "bloggs")
};
try {
int status = client.executeMethod(post);
post.setRequestBody(data);
byte[] responseBody = post.getResponseBody();
System.out.println(new String(responseBody));
} finally {
post.releaseConnection();
}
}
}
程式的Output结果是:
<body>
<form action="return.jsp" method="POST">
User name:<input type=text name=NAME value="" size=8 maxlength=8><br>
Password: <input type=text name=PASS value="" size=8 maxlength=8><br>
<input name="submit" type=submit value="submit">
</form>
</body>
可是小弟期待的结果是:
HiHi~ Joe Your password : bloggs
请问是不是少了什麽步骤呢?
ps:
http://127.0.0.1:7070/httpclienttest/body/就是小弟html档案的URL~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.26.190
1F:推 gconline:1 12/01 12:53