gpt4 book ai didi

java - 客户计算机上的 Apache httpclient 超时(处理请求时捕获 I/O 异常 : Connection timed out

转载 作者:太空宇宙 更新时间:2023-11-04 14:30:44 25 4
gpt4 key购买 nike

我在尝试使用 Apache HttpClient 3.0 通过 Java 代码连接和查询 Rally 时遇到超时问题

我使用 xmlhttprequest 确实没有遇到这个问题。

除了出现故障的机器之外,我无法在任何机器上重现此问题。由于主机是 https,这可能是 cacerts 问题吗?有没有办法检查代理?有任何记录建议可以获取更多信息吗?

谢谢!

错误信息是:org.apache.commons.httpclient.HttpmethodDirectorexecuteWithRetry信息:处理请求时捕获 I/O 异常(java.net.ConnectException):连接超时:连接。

他们正在运行 java jdk 1.6。

protected String doGet(HttpClient httpClient, GetMethod getMethod)
throws IOException
{
httpClient.getState().setCredentials(new AuthScope(this.host, this.port, null), new UsernamePasswordCredentials(this.username, this.password));
httpClient.getParams().setParameter("http.socket.timeout", new Integer(1000000));
getMethod.setDoAuthentication(true);
getMethod.getParams().setParameter("http.socket.timeout", new Integer(1000000));
getMethod.addRequestHeader("X-RallyIntegrationName", this.integrationName);
getMethod.addRequestHeader("X-RallyIntegrationVendor", this.integrationVendor);
getMethod.addRequestHeader("X-RallyIntegrationVersion", this.integrationVersion);
//getMethod.addRequestHeader("X-RallyIntegrationOS", getOSInfo());
//getMethod.addRequestHeader("X-RallyIntegrationPlatform", getProductInfo());
getMethod.addRequestHeader("X-RallyIntegrationLibrary", "Apache Commons HTTP Client 3.0");
try
{
double timeBefore = System.currentTimeMillis() / 1000;
int result = httpClient.executeMethod(getMethod);
double timeAfter = System.currentTimeMillis() / 1000;
System.out.println("Seconds to query for Workspace: " + (timeAfter - timeBefore));
if (result != 200) {
throw new IOException("Http GET Failed" + getMethod.getStatusLine());
}
String response = getMethod.getResponseBodyAsString();
System.out.println(response);
return response;
}
finally
{
getMethod.releaseConnection();
}

}}

最佳答案

您可以使用适用于 Java 的 Rally REST 工具包吗:https://github.com/RallyTools/RallyRestToolkitForJava

这可以处理您上面编写的大量代码(并且是使用较新版本的 Apache Http 组件 - 4.2.x 构建的)

关于java - 客户计算机上的 Apache httpclient 超时(处理请求时捕获 I/O 异常 : Connection timed out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26182388/

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