我正在尝试填写HTML表单,按表单的提交按钮,然后从中获取响应。
填写表格效果很好但我无法弄清楚如何按页面上的提交按钮。
我使用的是apache httpclient库。
我的代码是:
httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(pUrl);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("filter_response_time_http", "1"));
nvps.add(new BasicNameValuePair("filter_port", "80"));
nvps.add(new BasicNameValuePair("filter_country", "US"));
nvps.add(new BasicNameValuePair("submit", "Anzeigen"));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
entity = response.getEntity();
提交按钮的代码是:
<input onclick="doSubmit();" id="submit" type="submit" value="Anzeigen" name="submit" />