Can I override the Host header where using java's HttpUrlConnection class?

后端 未结 3 1651
日久生厌
日久生厌 2020-12-01 23:28

I\'m using the following code to open a http connection in java:

 URL url = new URL(\"http://stackoverflow.com\");
 HttpURLConnection conn = (HttpURLConnecti         


        
3条回答
  •  抹茶落季
    2020-12-02 00:05

    This used to work in the past, but it has been disabled as part of a security-fix. Apparently without a note in the changelog. There are even bugs like #7022056 for this at bugs.sun.com.

    There is a similar question for another header, where the answer goes more into the details, so I just link it instead of writing it myself. :-)

    The only workarounds seem to be setting sun.net.http.allowRestrictedHeaders to true or use another http-library like the already mentioned http components.

提交回复
热议问题