【问题标题】:PostMethod/HttpClientPostMethod/HttpClient
【发布时间】:2015-04-22 16:12:37
【问题描述】:

我需要使用 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);
}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 我期待 XML 响应。由于这是 http post 请求,我想隐藏我的 URL 参数。除了 URL 参数,我还需要发布 XML。我不能同时做这两个(编码 URL 参数 + 发布 XML)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2021-03-19
    相关资源
    最近更新 更多