Android HttpURLConnection 无法与 cgi-bin 一起使用?

发布于 2024-10-20 04:48:42 字数 1303 浏览 1 评论 0 原文

我有简单的代码:

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) **

如何将数据上传到类似的网址?

I have simple code :

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();
    ...

If I have urlStr = "http://samlib.ru/w/waliduda_a_a/molochnischituran1.shtml" - all is work fine.
If I use urls like urlStr = "http://samlib.ru/cgi-bin/areader?q=jlist" - I got a error in connection.getInputStream();

**
03-04 15:37:52.459: ERROR/DataReader::loadDataFromInet(17281): Failed loading http://samlib.ru/cgi-bin/areader?q=jlist
03-04 15:37:52.459: ERROR/DataReader::loadDataFromInet(17281): java.io.FileNotFoundException: http://samlib.ru/cgi-bin/areader?q=jlist
03-04 15:37:52.459: ERROR/DataReader::loadDataFromInet(17281): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
**

How can I upload data to a similar url?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城空念 2024-10-27 04:48:42

发生这种情况的原因有几个。我个人看到的是,当我输入随后重定向的 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!

许久 2024-10-27 04:48:42

看起来你的 cgi-bin/areader 没有找到。获取 HTTP/404 响应代码:

wget http://samlib.ru/cgi-bin/areader?q=jlist
--2011-03-04 09:03:17--  http://samlib.ru/cgi-bin/areader?q=jlist
Resolving samlib.ru... 81.176.66.171
Connecting to samlib.ru|81.176.66.171|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2011-03-04 09:03:17 ERROR 404: Not Found.

更正该代码,然后重试。

It looks like your cgi-bin/areader is not found. Getting an HTTP/404 response code:

wget http://samlib.ru/cgi-bin/areader?q=jlist
--2011-03-04 09:03:17--  http://samlib.ru/cgi-bin/areader?q=jlist
Resolving samlib.ru... 81.176.66.171
Connecting to samlib.ru|81.176.66.171|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2011-03-04 09:03:17 ERROR 404: Not Found.

Correct that then try again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文