How to customise “host” header in Java http client

跟風遠走 提交于 2019-11-29 11:11:49

The behavior from the Java11 client code seems correct. The Host section elaborates on the details. By the way, from the documentation of HttpRequest builder header(String name, String value) :

*    @throws IllegalArgumentException if the header name or value is not
*    valid, see <a href="https://tools.ietf.org/html/rfc7230#section-3.2">
*    RFC 7230 section-3.2</a>, or the header name or value is restricted
*    by the implementation.

Update: See this, for answer pertaining to JDK/12.

As of Java 12 (EA build 22) it has been solved by additional property jdk.httpclient.allowRestrictedHeaders (see https://bugs.openjdk.java.net/browse/JDK-8213696).

So now one can override Host (or any other restricted header) by executing the code with: java -Djdk.httpclient.allowRestrictedHeaders=host ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!