You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Yubao Liu (Jira)" <ji...@apache.org> on 2022/11/10 10:35:00 UTC
[jira] [Created] (HTTPCLIENT-2245) Content-Length is missing for HTTP/2
Yubao Liu created HTTPCLIENT-2245:
-------------------------------------
Summary: Content-Length is missing for HTTP/2
Key: HTTPCLIENT-2245
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2245
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient (async)
Affects Versions: 5.2-beta1
Environment: macOS, JDK 17
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)
Reporter: Yubao Liu
{code:java}
//> using lib "org.apache.httpcomponents.client5:httpclient5:5.2-beta1
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.apache.hc.core5.http.ContentType;public class A {
public static void main(String[] args) throws Exception {
CloseableHttpAsyncClient httpClient = HttpAsyncClientBuilder.create().useSystemProperties().build(); httpClient.start(); SimpleHttpRequest request = SimpleRequestBuilder.post("https://httpbin.org/anything")
.setBody("{\"msg\": \"hello\"}".getBytes(), ContentType.APPLICATION_JSON)
.build(); SimpleHttpResponse response = httpClient.execute(request, null).get();
System.out.println(response.getBodyText());
}
} {code}
According to the response, HttpClient doesn't set content-length automatically:
{code}
{
"args": {},
"data": "{\"msg\": \"hello\"}",
"files": {},
"form": {},
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"Host": "httpbin.org",
"Transfer-Encoding": "chunked",
"User-Agent": "Apache-HttpAsyncClient/5.2-beta1 (Java/17)",
"X-Amzn-Trace-Id": "Root=1-636cd35b-506ee990624aebd74fce87b9"
},
"json": {
"msg": "hello"
},
"method": "POST",
"origin": "114.246.97.66",
"url": "https://httpbin.org/anything"
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org