I came across similar requirement iso I used core javaJava's Connection URL API, - connection url apiURLConnection
. It was verymuch faster:
String myString = null;
URLConnection urlConn = null;
try{
URL url = new URL("enter url here");
urlConn = url.openConnection();
urlConn.setUseCaches(false);
HttpURLConnection httpConn = (HttpURLConnection)urlConn;
InputStream is=null;
if (httpConn.getResponseCode() >= 400) {
if(httpConn.getErrorStream()!=null){
is = httpConn.getErrorStream();
}else{System.out.println("no error");}
} else {
is = httpConn.getInputStream();
}
myString = IOUtils.toString(is, "UTF-8");
System.out.println(myString);
}catch(Exception e){
throw new RuntimeException("Exception while calling url:",e);
}