HttpsURLConnection间歇性地失败到同一个URL

时间:2010-05-15 18:41:42

标签: android https get

我想我的经历与此相同 http://groups.google.com/group/android-developers/msg/9d37d64aad0ee357
这是Android 1.5 SDK。 我碰巧在代码下面多次调用(在方法中) 相同的网址,它间歇性地失败。
当它失败时,没有异常,流是空的所以 readConnection失败,getResponseCode返回-1 禁用全局缓存,setDefaultUseCaches(false);

我想某处必须有某种url连接对象池。

关于如何解决这个问题的任何想法?

HttpURLConnection connection = null;
    try {
        URL url = new URL(this.url);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Authorization", "basic " +
        Base64Coder.encodeString(user + ":" + password));
        connection.setRequestProperty("User-Agent", userAgent);
        connection.connect();

        readConnection(connection.getInputStream());

        connection.disconnect();
    } catch (IOException ex) {
               reportException(ex, connection.getResponseCode())
    } catch (ParserException ex) {
               reportException(ex, connection.getResponseCode())
    } 

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)