[英]Java url.openConnection()
1) How can I send specific request headers whilst a url.openConnection()? 1)如何在url.openConnection()时发送特定的请求标头?
2) Also, how can I, in addition, turn the request to a POST and send post data as well? 2)另外,我如何才能将请求转为POST并发送帖子数据?
3) What document would you recommend to learn further more about url.openConnection() and its possibilities? 3)您建议使用哪个文档以进一步了解url.openConnection()及其可能性?
Thank you. 谢谢。
connection.addRequestProperty(headerName, headerValue);
You should call connection.setRequestMethod("POST");
您应该调用
connection.setRequestMethod("POST");
, then call connection.getOutputStream()
and write to this stream content of POST
request. ,然后调用
connection.getOutputStream()
并将POST
请求的内容写入此流。
google: "java http post example" brings tons of documentation. google:“ java http post示例”带来了大量文档。 Here is the first one: http://www.exampledepot.com/egs/java.net/post.html
这是第一个: http : //www.exampledepot.com/egs/java.net/post.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.