问题描述
我在我的 java 应用程序中使用 4.5.13 版的 apache http 客户端来发送 post 请求。我使用以下代码行来设置 http 客户端。
SocketConfig socketConfig = SocketConfig.custom()
.setSoKeepAlive(true)
.setTcpNoDelay(true)
.build();
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setMalformedInputAction(CodingErrorAction.IGnorE)
.setUnmappableInputAction(CodingErrorAction.IGnorE)
.setCharset(Consts.UTF_8)
.setMessageConstraints(messageConstraints)
.build();
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setExpectContinueEnabled(true)
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM,AuthSchemes.DIGEST))
.setContentCompressionEnabled(true)
.build();
BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
connectionManager.setSocketConfig(socketConfig);
connectionManager.setConnectionConfig(connectionConfig);
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(defaultRequestConfig)
.build();
我通过
发送数据CloseableHttpResponse response = httpClient.execute(postRequest);
我遇到的问题是,当我查看消息的发送方式(使用 tshark)时,我可以看到应用程序数据被分成两条消息。第一个在 httpClient.execute(postRequest) 之后大约 0.5ms 离开我的系统,但第二个部分在第一个之后大约 10ms-20ms 发送。看起来第二部分正在等待接收消息第一部分的确认。我尝试更改很多配置(缓冲区大小、TcpNoDelay、不同的 TLS ...),但无法弄清楚是什么导致了这种行为。
我也尝试过 http.net 客户端发送 post 请求。使用这个客户端,消息也被分成两条消息,但它们都紧接着发送(大约有 0.3 毫秒的延迟)。
我对网络还很陌生,所以如果我没有很好地解释它(我不知道所有的具体措辞),我会很感激有帮助的答案并预先道歉。
谢谢
解决方法
尝试禁用 expect-continue
握手。