URLConnection getContent() return null

。_饼干妹妹 提交于 2019-12-13 08:38:13

问题


I use the following method to get a bitmap input stream:

    private InputStream getInputStream(String urlString) throws MalformedURLException, IOException {
    URL url = new URL(urlString);
    URLConnection connection;
    connection = url.openConnection();
    //connection.setUseCaches(true); 
    Object response = connection.getContent();
    if (!(response instanceof InputStream))
        throw new IOException("URLConnection response is not instanceof InputStream");

    return (InputStream)response;
}

It works great on Android 2.3 (GalaxyS2) but on Android 2.2 (GalaxyS) response = null.

The remote url is a bitmap.

Any ideas?


回答1:


connection = url.openConnection();
connection.connect(); // <-- does it work if you add this line?
Object response = connection.getContent();


来源:https://stackoverflow.com/questions/8179658/urlconnection-getcontent-return-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!