java.net.SocketException:连接超时时> 0的连接重置

时间:2018-02-13 14:03:43

标签: java apache-commons-httpclient

我正在调用api来发送带有java apache公共客户端的短信,看起来设置超过0的超时会返回“java.net.SocketException:Connection reset”错误。

这是代码示例

// creating the http client
HttpClient client = new HttpClient();

设置连接时间超过10秒(我收到成功的回复           我删除这部分代码后

client.getHttpConnectionManager().
getParams().setConnectionTimeout(10000);

其余代码

//creating the request method
GetMethod method = new GetMethod(smsUrl);

// setting its params  
method.setQueryString(new NameValuePair[] { 
        new NameValuePair("username", user), 
        new NameValuePair("password", pass), 
        new NameValuePair("action", "sendsms"), 
        new NameValuePair("from", "Woosh"),
        new NameValuePair("to", toMobile), 
        new NameValuePair("text", textBody)
    });

//calling the method
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
        new DefaultHttpMethodRetryHandler(3, false));

int statusCode = client.executeMethod(method);

1 个答案:

答案 0 :(得分:0)

问题已解决,这是由我打电话的api的服务器引起的问题。不确定它是什么