通过POST将XML文件发送到Java中的RESTful服务

SNp*_*Npn 1 java xml rest

我需要使用POST将XML文件发送到Web服务.我有一个客户端应用程序,它创建一个XML文件,存储发送到Web应用程序所需的所有信息,但我不知道如何发送它.

我的XML看起来像这样:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Comment>
  <Poll_ID>2</Poll_ID>
  <Name>wpoon</Name>
  <Text>asdasdas</Text>
  <Timestamp>2012-10-14T10:30:25</Timestamp>
</Comment>
Run Code Online (Sandbox Code Playgroud)

我将发送给它的RESTful服务具有以下URL:

http://localhost:8080/TESTINGrestful/rest/polls/comment
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我如何做到这一点,任何帮助将不胜感激.

Abd*_*aly 12

有一个很好的例子,在这里 Apache的HttpClient的:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://localhost:8080/TESTINGrestful/rest/polls/comment");
StringEntity input = new StringEntity("<Comment>...</Comment>");
input.setContentType("text/xml");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
Run Code Online (Sandbox Code Playgroud)