Android应用程序不信任证书

时间:2011-11-02 08:43:08

标签: android certificate

我有证书可以保护我的网站,通过以下方式认证:Thawte DV SSL CA,Thawte,Inc。

现在我创建了一个连接到该站点的Web服务的android应用程序。 它只用于http://www.myserver.com时工作正常。

但是现在已经安全了,并且https://www.myserver.com我遇到了一些问题。

我使用2部手机测试我的应用程序。

  • HTC Desire S with Android 2.3.3(有SD卡)

  • 华为Ideos X5与Android 2.2.1(无SD卡)

HTC连接到https没有任何问题。 然而,华为提供了“不可信任的证书例外”。

我以前尝试连接的代码如下:

public String performRequest(String message, String url, Context context) throws IOException {

    AndroidHttpClient hc = AndroidHttpClient.newInstance("Android",context);
    Log.d(MobileConnectorApplication.APPLICATION_TAG, "NETWORK - Message to send: "+ message);
    HttpPost p = new HttpPost(url);

    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setSoTimeout(httpParams, threeMinutes );
    p.setParams(httpParams);

    try{
        if (message != null)
            p.setEntity(new StringEntity(message, "UTF8"));
    }catch(Exception e){
        e.printStackTrace();
    }
    p.setHeader("Content-type", "application/json");

    String response = "";

    HttpContext httpcontext = new BasicHttpContext();
    httpcontext.setAttribute(ClientContext.COOKIE_STORE, MobileConnectorApplication.COOKIE_STORE);
    try{
        HttpResponse resp = hc.execute(p,httpcontext);
        InputStream is = resp.getEntity().getContent();
        response = convertStreamToString(is);
        int httpResponsecode = resp.getStatusLine().getStatusCode() ;
        checkResponse(url, message, response, httpResponsecode);
        Log.d(MobileConnectorApplication.APPLICATION_TAG, String.format("NETWORK - Response %s : %s", httpResponsecode, response.length() > 150 ? response.subSequence(0, 150): response));

    } finally{
        hc.close();
    }
    return response;
 }

这部分代码是几个月前由其他人制作的,而他并不是要改变它,而且我对这些连接的了解也不是很好。

有人可以帮帮我吗?提前谢谢!

0 个答案:

没有答案