gpt4 book ai didi

android - Ice Cream Sandwich 中 HttpURLConnection 的 FileNotFoundException

转载 作者:IT王子 更新时间:2023-10-28 23:51:15 29 4
gpt4 key购买 nike

我有一个 Android 应用在 Android 2.x 和 3.x 上运行良好,但在 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();

当应用程序在 Android 4.x 上运行时,getInputStream() 调用会导致 FileNotFoundException。当相同的二进制文件在早期版本的 Android 上运行时,它会成功。这些 URL 在 Web 浏览器和 curl 中也可以正常工作。

显然 HttpURLConnection 在 ICS 中有所改变。有谁知道发生了什么变化,和/或修复可能是什么?

最佳答案

尝试删除 setDoOutput 调用。取自此博客: a blog

编辑:使用 POST 调用时需要这样做。

关于android - Ice Cream Sandwich 中 HttpURLConnection 的 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9365829/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com