1) 如何在 url.openConnection() 时发送特定的请求 header ?
2)另外,我怎样才能将请求转换为 POST 并发送 post 数据?
3) 您会推荐什么文档来进一步了解 url.openConnection() 及其可能性?
谢谢。
最佳答案
connection.addRequestProperty(headerName, headerValue);
您应该调用
connection.setRequestMethod("POST");
,然后调用connection.getOutputStream()
并写入的流内容POST
请求。google:“java http post 示例”带来了大量文档。这是第一个:http://www.exampledepot.com/egs/java.net/post.html
关于Java url.openConnection(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9453609/