【发布时间】:2015-07-04 05:28:50
【问题描述】:
在 java 中有没有一种方法可以使用 PostMethod 或 HttpPost 以及 url 参数来发布 XML?我正在做类似下面的事情,但它不起作用。
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();
// "https://mytest.com?z=123&b=abc&c=%10"
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 jakarta-ee http-post httpclient xml-rpc