如何在java中发送HTTP标头
java 中是否可以通过 URL 连接发送 Http 标头? 我使用套接字进行了此工作,但遇到了防火墙问题,这似乎不是 URLConnection 的问题。 通过查看 API,我得到的印象是 URLConnection 中的输出方法只是用于填写表单等,或者它们可以用于发送我自己的 HTTP 标头吗?
Is it possible to send a Http header via a URL connection in java? I had this working using sockets, but ran into issues with a firewall which don't seem to be a problem with URLConnection. From looking at the API I get the impression that the output methods in URLConnection are just for filling in forms etc, or can they be used to send my own HTTP headers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您想要的方法是 setRequestProperty。
Yes, the method you want is setRequestProperty.
您想要的方法是 setRequestProperty,但我建议使用 Apaches HttpClient。 通过这个库,您可以完全控制要发送的请求。
http://hc.apache.org/httpclient-3.x/tutorial。 html
The method you want is setRequestProperty, but I would recommend to use Apaches HttpClient. With this library you have total control over the request you want to send.
http://hc.apache.org/httpclient-3.x/tutorial.html