mardi 4 août 2015

Android: HttpURLConnection redirects - probably cached

I have problem with HTTP calling, when I have multiple redirects and multiple calls. Lets have following code:

con = (HttpURLConnection) (new
URL("http://server/?function=auth/fetch_internal_ip")).openConnection();
HttpURLConnection.setFollowRedirects(false);
con.setRequestMethod("GET");
con.setDoInput(true);
con.setDoOutput(true);
con.setConnectTimeout(1000);
con.setReadTimeout(1000);
con.connect(); StringBuffer buffer = new StringBuffer();
is = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null)
buffer.append(line).append("\r\n");
is.close();
con.disconnect();
is = null;
ip = buffer.toString().trim();

For first using works perfectly, but for any other in the future are not redirects followed. Only reinstall of app or restart phone helps.

Where could be a problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire