I am currently using this code to retrieve data from a server
public static String getResponse(String URL) throws IOException{ try{ String response_string; StringBuilder response = new StringBuilder(); URL url = new URL(URL); HttpURLConnection httpconn = (HttpURLConnection) url.openConnection(); if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK){ BufferedReader input = new BufferedReader(new InputStreamReader(httpconn.getInputStream())); String strLine = null; while ((strLine = input.readLine()) != null){ response.append(strLine); } input.close(); response_string = response.toString(); } httpconn.disconnect(); return response_string; } catch(Exception e){ throw new IOException(); } }
But it looks like it stores the cache, maybe I'm not sure, but if I change the data on the server and open the activity again, it will still remain the same on the application. I used HttpClient , which worked well before, but since it is deprecated since API 22 I changed it to HttpURLConnection . So can this be fixed?
source share