I have an app that executes a Get method to a web server via HttpURLConnection. It works fine on the test server, but fails on the live server. Investigation shows that the live server is doing a rediect (status 302 gets returned). How do I get HttpURLConnection to follow the redirect: I've tried setting the instanceFollowRedirects to true, to no avail.
Code snippet is:
URL url = new URL("<<....>>");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
I'm sure that this must be a common issue, but can't find any obvious solutions.
OK - first I don't think that I should be setting connection parameters after it's been opened! Even so, the follow redirects seems to default to true, so why doesn't it work? I know that the rediect doesn't require further intervention because I can use the Firefox poster utility to quite happily hit the URL.