Android无对等证书异常

时间:2014-04-08 09:53:34

标签: java android ssl https httpclient

在我的Android应用程序中,我使用 http 链接从服务器获取JSON响应,现在他们更改为 https 。我的代码返回无对等证书例外。

在Android中使用 https 从服务器获取响应需要做些什么。这是我用于从服务器获取 http 的响应的代码。

public static DefaultHttpClient httpClient;
public static ResponseHandler<String> resHandler;
public static List<NameValuePair> nameValuePairs;
public static HttpPost httpPost;

     ....

httpClient = new DefaultHttpClient();
resHandler = new BasicResponseHandler();
httpPost = new HttpPost("https://www.xxx.com/.../user/renting");
nameValuePairs = new ArrayList<NameValuePair>(6);

nameValuePairs.add(new BasicNameValuePair("parking_spot_id".trim(),
        spotID));
    ....
for (int i = 0; i < array.length; i++) {
    nameValuePairs.add(new BasicNameValuePair("date[]", array[i]));
}

try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    jsonResponse = httpClient.execute(httpPost, resHandler);
    Log.e("rent by day", jsonResponse);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

以上代码适用于 http

1)我需要为 https 获得什么。

2)代码有哪些变化。

请帮帮我。

0 个答案:

没有答案
相关问题