所以我有以下代码:
public void SendToApplication(HttpServletRequest request) throws IOException, TransformerException {
BufferedReader br = new BufferedReader(new FileReader(new File("CreatePoll.xml")));
String line;
StringBuilder sb = new StringBuilder();
while((line=br.readLine())!= null) sb.append(line.trim());
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://localhost:8080/cs9322.simple.rest.doodle/rest/polls/comment");
StringEntity input = new StringEntity(sb.toString());
input.setContentType("text/xml");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
HttpEntity entity = response.getEntity();
}
它读取一个 XML 文件 (CreatePoll.xml),
<Comment xmlns:xs="http://localhost:8080/cs9322.simple.rest.doodle/CommentSchema">
<Poll_ID>2</Poll_ID>
<Name>Bob</Name>
<Text>testing junk</Text>
<Timestamp>2012-10-14T12:37:04</Timestamp>
</Comment>
并将其发布到 Web 服务,我现在遇到的问题是在发送之后尝试从 Web 服务接收 XML 响应。我打算接收的 XML 是:
<comment>
<address>
</address>
</comment>
有人可以在这里帮助我吗,将不胜感激!