如何在java中发送HTTP标头

发布于 2024-07-18 10:19:31 字数 159 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听不够的曲调 2024-07-25 10:19:31

是的,您想要的方法是 setRequestProperty

Yes, the method you want is setRequestProperty.

寒尘 2024-07-25 10:19:31

您想要的方法是 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文