相关疑难解决方法(0)

冰淇淋三明治中HttpURLConnection的FileNotFoundException

我有一个适用于Android 2.x和3.x的Android应用程序,但在Android 4.x上运行时会失败.

问题出在这部分代码中:

URL url = new URL("http://blahblah.blah/somedata.xml");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();

InputStream inputStream = urlConnection.getInputStream();
Run Code Online (Sandbox Code Playgroud)

当应用程序在Android 4.x上运行时,getInputStream()调用会产生一个FileNotFoundException.当在早期版本的Android上运行相同的二进制文件时,它会成功.URL也适用于Web浏览器和curl.

显然HttpURLConnection,ICS中有些变化.有没有人知道发生了什么变化,和/或修复可能是什么?

android filenotfoundexception httpurlconnection

44
推荐指数
3
解决办法
4万
查看次数