gpt4 book ai didi

java - 使用 Apache HTTPClient 提交棘手的表单数据

转载 作者:行者123 更新时间:2023-11-29 09:12:13 24 4
gpt4 key购买 nike

这是我的代码:

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", "example@example.com"));
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,我很困惑。此外,复选框没有 value,因此我无法检查它们是否已选中。

感谢您的帮助!!

最佳答案

您不会得到预期的响应。

comb.php 的响应取决于 html 表单。

在您的 html 表单中未指定值。所以我看不到 comb.php 如何测试复选框。

 <td><input type="checkbox" name="cachingurl0"/></td>
<td><a href="http://video.google.com/?hl=en&tab=wv">http://video.google.com/?hl=en&tab=wv</a></td>

值(value):

 <td><input type="checkbox" name="cachingurl0" value="checked" /></td>

1.) 您还需要一个具有类似 GUI 形式的 java 应用程序(例如 Swing 形式的应用程序)。您可以在此处选中或取消选中所需的复选框。

2.) 您必须将适当的变量传递给 comb.php。例如:

if (myCheckB0.checked) { nameValuePairs.add(new BasicNameValuePair("cachingurl0", "checked"));}
if (myCheckB5.checked) { nameValuePairs.add(new BasicNameValuePair("cachingurl5", "checked"));

关于java - 使用 Apache HTTPClient 提交棘手的表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11660699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com