0
有谁知道如何使用HttpClient库在Java Eclipse中使用发布请求更新页面?目前,这是我,但是当我 执行它,我得到找不到网页错误:如何向HttpClient发送发布请求
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
}
}
啊对不起,我的意思是那里有另一个真正的网址,如neopets.com/neopet.xml。就像那种格式,它的一个锁定页面,并且已经使用另一个帖子请求进入该页面。 – user1558027 2012-08-02 18:11:51