如何将XML请求发送到Web服务

时间:2013-10-02 20:28:47

标签: java xml web-services

我已经使用wsimport生成了Web服务类,现在我应该向此Web服务发送一个XML请求(给定的特定格式),该请求返回XML响应,然后我可以在我这边使用该XML响应。如何创建我应该发送给webservice的自定义XML请求。那里有任何文件吗?

1 个答案:

答案 0 :(得分:3)

有很多方法可以做到这一点..

其中一个正在使用HttpClient from Apache 并执行这样的POST

PostMethod post = new PostMethod("http://jakarata.apache.org/");
NameValuePair[] data = {
  new NameValuePair("user", "joe"),
  new NameValuePair("password", "bloggs")
};
post.setRequestBody(data);
post.setRequestHeader("Content-type", "application/xhtml+xml");
// execute method and handle any error responses.
...
InputStream in = post.getResponseBodyAsStream();
// handle response.
相关问题