Android:与targetSdkVersion> = 11的神秘http连接问题

时间:2012-07-09 17:52:28

标签: android

使用来自两个文件的HttpClient从远程主机读取配置数据的Android库。一切正常,直到我使用11以上的targetSdkVersion测试它。现在第一个http请求失败,一般例外(我认为)。

我的想法是第二个请求以某种方式中断第一个请求,导致它失败。但为什么只在sdk版本11+?

以下是连接类的代码段:

import org.apache.http.client.HttpClient;
public static String readUrl(String url, boolean isCompressed) throws IOException {
    String result = "";

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 15000);
    HttpConnectionParams.setSoTimeout(httpParameters, 15000);

    HttpClient client = new DefaultHttpClient(httpParameters);
    HttpGet get = new HttpGet(url);
    get.addHeader("Cache-Control", "no-cache");
    if(isCompressed) get.addHeader("Accept-Encoding", "gzip,deflate");

    HttpResponse response = null;
    try {
        response = client.execute(get);
    } catch (ClientProtocolException e) {
        Log.e("debug", "ClientProtocolException HttpClient execute "+e.getMessage());
    } catch (IOException e) {
        Log.e("debug", "IOException HttpClient execute "+e.getMessage());
    } catch (Exception e) {
        Log.e("debug", "Gen Exception HttpClient execute "+e.getMessage());
    }


    result = readResponse(response);        
    client.getConnectionManager().shutdown();
    return result;
}

触发了一般异常,e.getMessage()返回null - 这更令人困惑。这是我得到的唯一错误。我也试过用httpURLConnection重写这个 - 结果相同。

有什么想法吗?

0 个答案:

没有答案