开发者

Android HttpURLConnection not working with cgi-bin?

开发者 https://www.devze.com 2023-02-14 16:15 出处:网络
I have simple code : URL url; BufferedReader in = null; HttpURLConnection connection; InputStream is = null;

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.Fi开发者_如何学JAVAleNotFoundException: 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?


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号