gpt4 book ai didi

java - 找出 HttpClient 超时的系统默认值

转载 作者:搜寻专家 更新时间:2023-11-01 03:51:43 25 4
gpt4 key购买 nike

如何找出 HttpClient 4.3 的实际超时值?我知道如何显式设置它们,但我想知道如果我不覆盖它们,哪些值会被隐式使用。

例子

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.params.HttpParams;

public class HttpClientDefaults
{

public static void main(String[] args)
{
RequestConfig config = RequestConfig.custom().build();
System.out.println("ConnectionRequestTimeout: " + config.getConnectionRequestTimeout());
System.out.println("ConnectTimeout: " + config.getConnectTimeout());
System.out.println("SocketTimeout: " + config.getSocketTimeout());
CloseableHttpClient client = HttpClientBuilder.create().setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
HttpParams params = client.getParams();
System.out.println(params.getParameter("http.socket.timeout"));
}

}

输出

ConnectionRequestTimeout: -1
ConnectTimeout: -1
SocketTimeout: -1
Exception in thread "main" java.lang.UnsupportedOperationException

client.getParams() 抛出 java.lang.UnsupportedOperationException 异常。有人知道读出将要使用的实际值的方法吗?

最佳答案

套接字、连接和连接请求超时的默认值为 0(无超时)

关于java - 找出 HttpClient 超时的系统默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25567577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com