本文介紹了如何覆蓋 http-header “主機(jī)"在 HttpURLConnection 中?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號..
我的代碼如下:
URL url = new URL("1.0.0.25/otfg/services");
HttpURLConnection cnx = url.openConnection();
cnx.setRequestProperty("Host", "example.org");
但是當(dāng)我使用 tcpdump 記錄傳出的包時(shí),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主機(jī)"在發(fā)送過程的后期被覆蓋,如果是,我該如何避免這種行為.
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.
推薦答案
重復(fù)問題.
最后一條評論解決了我的問題:
The last comment solved my problem:
System.setProperty("sun.net.http.allowRestrictedHeaders", "true")
或者在虛擬機(jī)啟動(dòng)時(shí):
-Dsun.net.http.allowRestrictedHeaders=true
這篇關(guān)于如何覆蓋 http-header “主機(jī)"在 HttpURLConnection 中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!