本文介紹了如何覆蓋 http-header “主機"在 HttpURLConnection 中?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我的代碼如下:
URL url = new URL("1.0.0.25/otfg/services");
HttpURLConnection cnx = url.openConnection();
cnx.setRequestProperty("Host", "example.org");
但是當我使用 tcpdump 記錄傳出的包時,http-header "Host" 是 1.0.0.25.
But when I log the outgoing packages with tcpdump the http-header "Host" is 1.0.0.25.
可能是http-header主機"在發送過程的后期被覆蓋,如果是,我該如何避免這種行為.
Could it be that the http-header "Host" is overwritten at a later stage of the sending process, if yes how can I avoid this behavior.
推薦答案
重復問題.
最后一條評論解決了我的問題:
The last comment solved my problem:
System.setProperty("sun.net.http.allowRestrictedHeaders", "true")
或者在虛擬機啟動時:
-Dsun.net.http.allowRestrictedHeaders=true
這篇關于如何覆蓋 http-header “主機"在 HttpURLConnection 中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!