有谁知道我将如何使用带有 HttpClient 库的 Java Eclipse 中的发布请求来更新页面?目前这就是我所拥有的,但是当我执行它时,我得到一个找不到页面的错误:
public void update() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://examplepage.xml");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("_action", "<BasicPage><title>New Title</title></BasicPage>"));
nameValuePairs.add(new BasicNameValuePair("_method", "post"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String info = (""+EntityUtils.toString(entity));
System.out.println(info);
System.out.println(response.getEntity().getContent());
System.out.println(response);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}