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

后端 未结 3 1657
日久生厌
日久生厌 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:14

    The Host header is filled by the HttpURLConnection based on the URL. You can't open foo.com with Host=bar.com. From the RFC

    The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource (generally an HTTP URL)

    Btw, you can also try apache http components.

提交回复
热议问题