2013-10-02 92 views
3

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

+0

一个POST http://stackoverflow.com/questions/4041078/what -is-the-best-way-to-send-xml-data-to-webservices-jaxws有人已经在这里回答了。 – Zeus

回答

3

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

其中之一是使用HttpClient from Apache和执行这样的

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. 
+0

这是如何创建XML请求的? – yogsma

+0

你只需要发送一个请求,该请求的主体被一个XML字符串填充为参数。'new NameValuePair(“param”,“my xml string”)' – thiagoh

相关问题