我正在尝试使用以下代码从我的网站下载一些数据:
URL url = new URL (Url );
StringBuilder jsonResults = new StringBuilder ();
HttpURLConnection conn = (HttpURLConnection)url.OpenConnection ();
Java.IO.InputStreamReader inp = new Java.IO.InputStreamReader (conn.InputStream);
虽然我尝试下载的网址在网址上打开时看起来不错,但是当我使用移动设备上传代码时,返回的代码如下所示:
<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>
什么可能导致这个问题?
答案 0 :(得分:1)
HTTP 302状态代码不是错误,只是表示临时重定向到另一个URL。
默认情况下,Android HttpURLConnection
会自动跟进最多五个重定向。如果有更长的重定向链,它将无法工作,例如有一个重定向循环,或者其中一个重定向将协议从HTTP更改为HTTPS,反之亦然。
您显示的结果文档仅显示通用302重定向页面,但没有指示实际的HTTP级别状态代码是什么。