我正在尝试发送带有名为“:path”的标头的POST请求(HTTP / 2),但看起来Java 11中的HttpClient不允许以冒号开头的标头。
这个标头使用 HTTP/2 应该没问题。
这就是我的代码的样子:
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest mainRequest = HttpRequest.newBuilder()
.uri(URI.create("xxxx"))
.setHeader(":method", "POST")
.setHeader(":path", "xxxxx")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = null;
try {
response = httpClient.send(mainRequest, HttpResponse.BodyHandlers.ofString());
} catch (Exception e) {
e.printStackTrace();
}
难道我做错了什么?