如何向 web 服务发送 XML 请求

3

我使用wsimport生成了web服务类,现在我需要发送一个XML请求(给定特定格式)到这个WebService,它将返回一个XML响应,然后我可以在我的端上使用该XML响应。如何创建这个自定义的XML请求,我应该发送到WebService?是否有任何相关文档可供参考?


这里已经有人回答了:https://dev59.com/KlHTa4cB1Zd3GeqPRnek - Zeus
1个回答

3
有很多方法可以实现这个.. 其中之一是使用来自Apache的HttpClient并执行类似以下的POST: http://hc.apache.org/httpclient-3.x/
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.

这是如何创建XML请求的? - yogsma
你只需要发送一个请求,其中请求体作为参数填充了一个XML字符串.. new NameValuePair("param", "my xml string") - thiagoh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接