[JSP ] httpclient模擬submit問題
各位站內高手們麻煩解答小弟疑惑。
小弟想利用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
推
12/01 12:53, , 1F
12/01 12:53, 1F