如何在HTTP GET或HTTP put请求中发送xml文件?我正在使用restlet框架。 我新来这个,根据我读过的,我应该序列化XML。 这样做后,我怎么能发送它的HTTP请求?Restlet:在HTTP请求中发送xml
0
A
回答
1
即使你不使用一个结合了片断的库(我认为Restlet确实提供了一些简化),它很简单,就像你提到的一样,你需要的只是一个HTTP连接/请求,可能会消耗)XML。 所以除了Restlet特有的东西(希望其他人可以解释)之外,这里有一个“游击”的方法,只使用独立的部分。
要获得HTTP连接,您可以使用JDK功能(如果这样做不起作用,Apache HTTP客户端或async-http-client可以提供更多功能);是这样的:
URL url = new URL("http://myservice.mycompany.com:8080/path/to/service");
// configure settings here if/as necessary
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// if you need to post stuff, do:
conn.setRequestMethod("POST");
// need to set content type too possibly
conn.setDoOutput(true); // but only if you do POST stuff
OutputStream out = conn.getOutputStream();
// here you would output XML request
//...
out.close();
// and now read response
InputStream in = conn.getInputStream();
// and process it
// ...
in.close();
现在,作为生产/使用XML,您可以使用所有使用的输入/输出流读/写XML通常的工具。如果你喜欢数据绑定(来自XML的Java POJOs),JAXB是要走的路(javax.xml.bind。*); JDK 1.6及更高版本捆绑默认实现。
或者,您可以简单地使用Stax(javax.xml.stream。*)实现,例如Woodstox,通过简单调用读取/写入XML;对于奖励积分,请查看StaxMate,这可以相当简化这种风格。
相关问题
- 1. 在java中发送XML http请求
- 2. 使用XML发送HTTP请求
- 3. 发送HTTP请求
- 4. 发送HTTP请求
- 5. 在发布请求中发送http url作为请求参数
- 6. 发送HTTP请求(验证请求)
- 7. 在Ruby中发送HTTP/2 POST请求
- 8. 在Qt中发送HTTP请求
- 9. 在node.js中发送http请求
- 10. $ http不会在请求中发送Cookie
- 11. 在目标c中发送HTTP请求
- 12. 在Android中发送HTTP请求
- 13. Node.js在循环中发送http请求
- 14. HTTP在Swift中发送请求参数
- 15. 在Spring MVC中发送HTTP POST请求
- 16. 在http请求(Django)中发送page_size
- 17. 在oxwall中发送http请求
- 18. 在Perl中发送HTTP请求
- 19. 如何在android中发送http请求?
- 20. 发送HTTP POST请求
- 21. JAVA发送POST http请求
- 22. Http请求发送到BW
- 23. 同步发送http请求
- 24. 发送HTTP POST请求
- 25. Wit.ai POST /发送HTTP请求
- 26. 字API发送HTTP请求
- 27. 发送原始HTTP请求
- 28. 用swift发送http请求
- 29. NodeJS - TCP - 发送HTTP请求
- 30. MediaPlayer不发送HTTP请求?
什么样的服务器软件? – Michas
使用restlet,遵循休息的架构。 – SLA
将此信息添加到您的问题的内容和标题。 – Michas