Android HttpURLConnection 无法与 cgi-bin 一起使用?
我有简单的代码:
URL url;
BufferedReader in = null;
HttpURLConnection connection;
InputStream is = null;
InputStreamReader br = null;
setProgressTitle(progress, context.getString(R.string.loading));
setProgressMessage(progress, context.getString(R.string.loading_from_internet));
try {
url = new URL(urlStr);
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(Const.TIMEOUT);
is = connection.getInputStream();
...
如果我有 urlStr = "http://samlib.ru/w/waliduda_a_a/molochnischituran1.shtml" - 一切正常。 如果我使用像 urlStr = "http://samlib.ru/cgi-bin/areader?q=jlist" 这样的 url - 我在 connection.getInputStream(); 中遇到错误
** 03-04 15:37:52.459:错误/DataReader :: loadDataFromInet(17281):加载失败 http://samlib.ru/cgi-bin/areader?q=jlist 03-04 15:37:52.459:错误/DataReader :: loadDataFromInet(17281):java.io.FileNotFoundException:http://samlib.ru/cgi-bin/areader?q=jlist 03-04 15:37:52.459:错误/DataReader :: loadDataFromInet(17281):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521) **
如何将数据上传到类似的网址?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生这种情况的原因有几个。我个人看到的是,当我输入随后重定向的 URL 时,HttpURLConnection 不会处理该问题。我和你的反应一样,我用FF打了一下,效果很好。也有可能在接收端进行某种浏览器嗅探。
祝你好运!
There are a couple of reasons this might happen. Where I've personally seen it is when I've put in a URL that was subsequently redirected, HttpURLConnection doesn't handle that. I got the same response as you, I hit it with FF and it works fine. Its also possible that some sort of browser sniffing might be done on the recieving side.
Good Luck!
看起来你的 cgi-bin/areader 没有找到。获取 HTTP/404 响应代码:
更正该代码,然后重试。
It looks like your cgi-bin/areader is not found. Getting an HTTP/404 response code:
Correct that then try again.