Java 如何使用HttpClient发送post请求

Java 如何使用HttpClient发送post请求,java,eclipse,httpclient,Java,Eclipse,Httpclient,有人知道我将如何在JavaEclipse和HttpClient库中使用post请求来更新页面吗?目前这是我所拥有的,但是什么时候 我执行该命令时,发现一个页面未找到错误: public void update() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://examplepage.xml"); try { // Add

有人知道我将如何在JavaEclipse和HttpClient库中使用post请求来更新页面吗?目前这是我所拥有的,但是什么时候 我执行该命令时,发现一个页面未找到错误:

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
    }
}
public void update(){
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://examplepage.xml");
试一试{
//添加您的数据
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“_action”,“新标题”);
添加(新的BasicNameValuePair(“_方法”,“post”));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
字符串信息=(“”+EntityUtils.toString(实体));
系统输出打印项次(信息);
System.out.println(response.getEntity().getContent());
System.out.println(响应);
}捕获(客户端协议例外e){
//TODO自动生成的捕捉块
}捕获(IOE异常){
//TODO自动生成的捕捉块
}
}

您的代码看起来不错。检查页面URI或别名“examplepage.xml”是否确实存在或映射。还要检查它是否可以接受POST请求。

啊,很抱歉,我的意思是那里有另一个真实的url,比如neopets.com/neopet.xml。就像那种格式,它是一个锁定的页面,我已经用另一个post请求进入了那里。