开发者

fileNotFoundException when pointing to ebay.com from mobile [closed]

Closed. This question needs debugging details. It is not currently accepting开发者_开发知识库 answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 3 years ago.

Improve this question

If I pass http://www.ebay.com to this. Somewhere along the way ebay changes my url, perhaps a redirect. What's weird is Android java can't open the page.

u = new URL(txturl.getText().toString());

I get the error below as it apparently opening the new mobile site. I'm just wonder at what point my url changes and If I somehow stop this. It does not appear to happen if I point to yahoo, google, amazon or other major sites. I just noticed this in my testing.

Thanks.

09-07 16:08:08.739: INFO/System.out(360): >>>>>>>>>>>>>>>>>>>>> Unable to connect to **http://www.ebay.com - http://m.ebay.com?ebayref=http%3A%2F%2Fwww.ebay.com%3A80%2F%3Fredirect%3Dmobile**
09-07 16:08:08.739: WARN/System.err(360): **java.io.FileNotFoundException**: http://m.ebay.com?ebayref=http%3A%2F%2Fwww.ebay.com%3A80%2F%3Fredirect%3Dmobile
09-07 16:08:08.749: WARN/System.err(360):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162)
09-07 16:08:08.759: WARN/System.err(360):     at parser.XXXXXX.com.parserActivity.process(parserActivity.java:106)
09-07 16:08:08.759: WARN/System.err(360):     at parser.XXXXXX.com.parserActivity.access$0(parserActivity.java:68)
09-07 16:08:08.769: WARN/System.err(360):     at parser.XXXXXX.com.parserActivity$1.onClick(parserActivity.java:61)
09-07 16:08:08.779: WARN/System.err(360):     at android.view.View.performClick(View.java:2408)
09-07 16:08:08.779: WARN/System.err(360):     at android.view.View$PerformClick.run(View.java:8816)
09-07 16:08:08.789: WARN/System.err(360):     at android.os.Handler.handleCallback(Handler.java:587)
09-07 16:08:08.789: WARN/System.err(360):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-07 16:08:08.799: WARN/System.err(360):     at android.os.Looper.loop(Looper.java:123)
09-07 16:08:08.809: WARN/System.err(360):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-07 16:08:08.809: WARN/System.err(360):     at java.lang.reflect.Method.invokeNative(Native Method)
09-07 16:08:08.819: WARN/System.err(360):     at java.lang.reflect.Method.invoke(Method.java:521)
09-07 16:08:08.819: WARN/System.err(360):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-07 16:08:08.829: WARN/System.err(360):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-07 16:08:08.839: WARN/System.err(360):     at dalvik.system.NativeStart.main(Native Method)


Some websites force you into broken mobile versions - I keep a second browser on the phone with the user agent string claiming to be a desktop browser instead of a mobile one. You may need to do this for your app, and make it changeable or do updates as the website changes its implementation.


Solution (in my case)

In case when server response code is >= HTTP_BAD_REQUEST (greater than 400) method getInputStream(), of class HttpURLConnectionImpl throws FileNotFoundException (so you cannot open input stream).

Even if this file exist, your object will not give you input stream, because of server response code is >=400 - change response code on server or use annother class to connect.

09-07 16:08:08.749: WARN/System.err(360): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162)

Fragment of source code: http://www.docjar.com/html/api/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java.html

  867       @Override
  868       public InputStream getInputStream() throws IOException {
  869           if (!doInput) {
  870               throw new ProtocolException(Messages.getString("luni.28")); //$NON-NLS-1$
  871           }
  872   
  873           // connect before sending requests
  874           connect();
  875           doRequest();
  876   
  ...
  883           if (responseCode >= HTTP_BAD_REQUEST) {
  884               throw new FileNotFoundException(url.toString());
  885           }
  886   
  887           return uis;
  888       }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜