简体   繁体   English

如何打印HttpURLConnection发送的所有请求标头?

[英]How to print all the request headers which HttpURLConnection is sending?

I am using HttpURLConnection in one of my Java program to hit a HTTP URL via Java. 我在我的一个Java程序中使用HttpURLConnection通过Java访问HTTP URL。

I know I can set the request header value something like this. 我知道我可以像这样设置请求标头值。

connObj.setRequestProperty("User-Agent", "curl/7.29"); connObj.setRequestProperty(“ User-Agent”,“ curl / 7.29”);

But I want to print all the request headers which is generated by URLConnection. 但我想打印所有由URLConnection生成的请求标头。 Is that possible? 那可能吗?

How about calling getRequestProperties() which as the documentation states 如何调用文档中指出的getRequestProperties()

Returns an unmodifiable Map of general request properties for this connection. 返回此连接的常规请求属性的不可修改的Map。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM