private String fetchData(String url) { StringBuilder data = new StringBuilder(); boolean isSuccess = false; HttpClient stageClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); RailyatriCookies railyatriCookies = getRailyatriCookies(); if (railyatriCookies != null) { ((DefaultHttpClient) stageClient).setCookieSpecs(railyatriCookies.getCookieSpecRegistry()); ((DefaultHttpClient) stageClient).setCookieStore(railyatriCookies.getCookieStore()); } httpGet.setHeader("Accept", "application/json"); httpGet.setHeader( "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22"); httpGet.setHeader("Accept-Encoding", "gzip,deflate,sdch"); try { HttpResponse response = stageClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = bufferedReader.readLine()) != null) { data.append(line); isSuccess = true; } } else { Log.e(tag, "Failed to access: " + url + ". status code = " + statusCode); isSuccess = false; } } catch (ClientProtocolException clientProtocolException) { clientProtocolException.printStackTrace(); Log.e(tag, clientProtocolException.getMessage()); isSuccess = false; } catch (IOException ioException) { ioException.printStackTrace(); Log.e(tag, ioException.getMessage()); isSuccess = false; } if (isSuccess) { return data.toString(); } else { return null; } }