1

I have an Android app which makes an http GET call. The code is pretty simple:

URL url = new URL(sUrl);
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
while ((str = in.readLine()) != null) {
    buff.append(str);
}
// do stuff with the data

Recently the call has stopped working, and I get a 301 Moved Permanently response. However the call works perfectly well from a browser.

What would cause this? Is it a deliberate attempt to reject my request? Is there anything I can change to get around this?

androidneil
  • 880
  • 1
  • 10
  • 21
  • 2
    you may want to add `urlc.setInstanceFollowRedirects(true);` (and cast urlc to HttpURLConnection) or just `HttpURLConnection.setFollowRedirects(true);` – njzk2 Oct 07 '15 at 16:50
  • 1
    it could also be related to http://stackoverflow.com/questions/1884230/java-doesnt-follow-redirect-in-urlconnection (https in redirect form an http url) – njzk2 Oct 07 '15 at 16:52
  • Thank you so much, one of the answers on the question you linked to has helped me out. (The answer by Nathan on Sept 25th 2014). Thanks again! – androidneil Oct 07 '15 at 17:15

0 Answers0