所以,在我的网站上,我使用了几个不同的 SSL 证书。一个用于根域“illution.dk”,一个用于我的子域“ci.illution.dk”。麻烦的是,当我使用 HttpPost 发起一个发布请求时,我请求一个像“https://ci.illution.dk/login/device”这样的 URL,它只是抛出一条错误消息说:
10-04 18:35:13.100: W/System.err(1680): javax.net.ssl.SSLException: hostname in certificate didn't match: <ci.illution.dk> != <www.illution.dk> OR <www.illution.dk> OR <illution.dk>
我认为这意味着它正在下载 illution.dk 的证书,然后看到它不支持 ci.illution.dk。但是,当我加载浏览器并浏览到“https://ci.illution.dk”时,一切都很好。我的安卓代码如下:
HttpClient httpclient = new DefaultHttpClient();
//appContext.getString(R.string.base_url)
HttpPost httppost = new HttpPost("https://ci.illution.dk/login/device");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", params[0]));
nameValuePairs.add(new BasicNameValuePair("password", params[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
return response;
} catch (ClientProtocolException e) {
Log.d("ComputerInfo", "Error while loggin in: ClientProtocolException");
return null;
} catch (IOException e) {
Log.d("ComputerInfo", "Error while loggin in: IOException");
e.printStackTrace();
return null;
} catch (Exception e) {
Log.d("ComputerInfo", "Error while loggin in");
e.printStackTrace();
return null;
}