[英]java.net.SocketException: Connection reset when connection time out >0
我正在调用一个API,以通过Java apache通用客户端发送短信,并且看起来将超时设置为0以上会返回“ java.net.SocketException:连接重置”错误。
这是一个代码示例
// 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);
问题已解决,这是由我正在调用的api服务器引起的。 不确定是什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.