的PostMethod / HttpClient的

时间:2015-04-22 16:12:37

标签: java http-post httpclient apache-httpclient-4.x

我需要使用URL参数和XML对以下URL发出http post请求。我正在尝试使用以下代码,但无法获得适当的响应。

URL - https://mytest.com?z=123&b=abc&c=%10

xml - <test>
        <data> This is test XML </data>
      </test>

public String getResponse(String xml) {

    HttpClient client = new HttpClient();
    String url="https://mytest.com";
    PostMethod pMethod = new pMethod(url);
    pMethod.addParameter("z","123");
    pMethod.addParameter("b","abc");
    pMethod.addParameter("c","%10");
    post.setRequestEntity(new StringRequestEntity(xml, "application/xml", "UTF-8"));
    client.executeMethod(pMethod);
}

1 个答案:

答案 0 :(得分:0)

请详细说明您的期望是什么样的回应?如果您只是在将xml字符串发送到给定网址时遇到问题,那么可能Send Xml string through POST method in java可以帮助您。