0

有谁知道我将如何使用带有 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
    }
}
4

1 回答 1

0

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

于 2012-08-02T17:57:39.090 回答