0

I am calling an api to send sms with a java apache common client, and it looks like setting a time out for more than 0 is returning a "java.net.SocketException: Connection reset" error.

Here is a the code sample

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

Setting a connection time out of 10 sec (I receive a successful response as soon as I remove this part of the code)

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

Rest of the code

//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);
sam winston
  • 162
  • 1
  • 13
  • Possible duplicate of [java.net.SocketException: Connection reset](https://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset) – Laurent B Feb 13 '18 at 14:16
  • @LarentB Its a different issue, mine is occurring because I am setting a connection time out. I get a successful response as soon as I don't provide any – sam winston Feb 13 '18 at 15:07

1 Answers1

0

The issue was sorted out, it was an issue caused by the server of the api I was calling. Not sure what was it though

sam winston
  • 162
  • 1
  • 13