如何在HttpURLConnection中覆盖http-header“Host”?
我的代码如下:
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。
可能是在发送过程的后期阶段覆盖了http-header“Host”,如果是,我该怎样才能避免这种行为。
重复的问题。
最后的评论解决了我的问题:
System.setProperty("sun.net.http.allowRestrictedHeaders", "true")
或者在VM启动时:
-Dsun.net.http.allowRestrictedHeaders=true