问题描述
我有一个Android应用程序的正常工作与Android 2.x和3.x,但它在Android 4.x版上运行时出现故障。
I have an Android app that works fine with Android 2.x and 3.x, but it fails when run on Android 4.x.
现在的问题是在本节的code:
The problem is in this section of code:
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();
当应用程序在Android 4.x的运行,在 FileNotFoundException异常的
。当相同的二进制文件在早期版本的Android上运行,它成功。该网址也很好地工作在Web浏览器,并与的getInputStream()
通话效果卷曲
。
When the application is running on Android 4.x, the getInputStream()
call results in a FileNotFoundException
. When the same binary is running on earlier versions of Android, it succeeds. The URLs also work fine in web browsers and with curl
.
显然,一些关于的HttpURLConnection
在ICS已经改变。没有任何人有任何想法发生了什么变化,和/或如何修复可能是什么?
Apparently something about HttpURLConnection
has changed in ICS. Does anybody have any idea what has changed, and/or what the fix might be?
推荐答案
尝试删除setDoOutput电话。摘自此博客:一个博客
Try removing the setDoOutput call. Taken from this blog:a blog
编辑:这是使用后打电话时,需要
This is needed when using a POST call.
这篇关于FileNotFoundException异常的HttpURLConnection的在冰淇淋三明治的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!