mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. dev
  3. Main content

android4.0中HttpURLConnection抛异常java.io.FileNotFoundException

2012-03-24 93hotness 0likes 0comments

最近把机器刷到4.0了
跑了一下自己的app,发现下载xml文件部分抛出异常:java.io.FileNotFoundException: http://www.jpfocus.com/xxxx.xml

可是在2.3的系统却可以正常下载

我的代码:


URL url = new URL(urlstr);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setRequestMethod("GET");
httpCon.setDoOutput(true);
httpCon.connect();


原因:
4.0中设置httpCon.setDoOutput(true),将导致请求以post方式提交,即使设置了httpCon.setRequestMethod("GET");
将代码中的httpCon.setDoOutput(true);删除即可

Tag: Nothing
Last updated:2012-03-24

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang