Question

I'm trying to download some data from my website with below code:

URL url = new URL (Url );
StringBuilder jsonResults = new StringBuilder ();
HttpURLConnection   conn = (HttpURLConnection)url.OpenConnection ();
Java.IO.InputStreamReader inp = new Java.IO.InputStreamReader (conn.InputStream);

while the url I try to download looks good when I open it on the url but when I download it with mobile above code returns a value like below:

<html>
<head><title> 302 Found
</title></head>
<body><h1> 302 Found
</h1>
The document has been temporarily moved to <A HREF="%s">here</A>.<hr />
Powered By <a href='http://www.litespeedtech.com'>LiteSpeed Web Server</a><br />
<font face="Verdana, Arial, Helvetica" size=-1>LiteSpeed Technologies is not responsible for administration and contents of this web site!</font></body></html>

What can cause this problem?

Was it helpful?

Solution

HTTP 302 status code is not an error but just indicates a temporary redirect to another URL.

By default, Android HttpURLConnection will follow up to five redirects automatically. It won't work if there's a longer redirect chain e.g. there's a redirect loop, or one of the redirects changes protocol from HTTP to HTTPS or vice versa.

The result document you show just shows a generic 302 redirect page but there's no indication what the actual HTTP level status code is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top