I want to set the timeout of a request. This is the code, I've got so far.
final HttpClient httpclient = HttpClients.createDefault();
final HttpPost httppost = new HttpPost(address);
httppost.setHeader("Accept", "text/xml");
httppost.setHeader("Content-type", "application/xml; charset=UTF-8");
httppost.setEntity(new StringEntity(body));
final HttpResponse response = httpclient.execute(httppost);
final HttpEntity entity = response.getEntity();
I've tried (does not work, keeps loading and ignores timeout)
// set the connection timeout value to 30 seconds (30000 milliseconds)
final HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
client = new DefaultHttpClient(httpParams);
and (this one throws java.lang.UnsupportedOperationException)
httpclient = HttpClients.createDefault();
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 6000);
Is there any other way for setting the timout? I don't really need the response so something like an asynchronous request could do the work too.
final HttpClient httpclient; = HttpClients.createDefault();you have extra ;CoreConnectionPNames.TIMEOUT?