2
這裏是我的代碼:使用Apache了HTTPClient提交棘手的表單數據
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.webcitation.org/comb.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair(??, ??));
nameValuePairs.add(new BasicNameValuePair("fromform", "2"));
nameValuePairs.add(new BasicNameValuePair("email", "[email protected]"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
System.out.println(e);
}
這裏就是我試圖模仿形式的HTML代碼:http://www.webcitation.org/69Qsz3Tdn
我想提交的網址http://video.google.com/?hl=en&tab=wv
,http://maps.google.com/maps?hl=en&tab=wl
等通過Java到PHP文件並讀取響應。由於href
沒有name
s,我很難過。此外複選框沒有value
s,所以我無法檢查它們是否被檢查。
感謝您的任何幫助!
你是什麼意思? hrefs根本不會被提交,它們就是這樣 - 鏈接。我假設在服務器端有一些將URL映射到複選框名稱的東西。 – 2012-07-26 00:38:24