我是新手。
我使用下面的代码与我的服务器进行交互。我的网站获得了Https安全性。
protected Void doInBackground(Void...params)
{
HttpClient httpClient=new DefaultHttpClient();
HttpPost httpPost;
ArrayList<NameValuePair> param= new ArrayList<NameValuePair>();
httpPost = new HttpPost("https://xxxx.co.in/xxx.php");
param.add(new BasicNameValuePair("mobileSerialNumber",mobileSerialNumber));
param.add(new BasicNameValuePair("NFCSupportedMobile",NFCSupportedMobile));
param.add(new BasicNameValuePair("ConnectedTo_REVUE_Wifi",ConnectedTo_REVUE_Wifi));
param.add(new BasicNameValuePair("ConnectedToWifi",ConnectedToWifi));
param.add(new BasicNameValuePair("ConnectedToMobileInternet",ConnectedToMobileInternet));
try {
httpPost.setEntity(new UrlEncodedFormEntity(param));
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
//read content
is = httpEntity.getContent();
} catch (Exception e) {
Log.e("Server Connection", "Server connection failed");
e.printStackTrace();
iconnectionProblem = true;
}
当我使用上面的代码请求我的服务器时,我得到了以下错误。
03-16 23:11:59.467 20262-20480/com.revu.revu W/System.err﹕ javax.net.ssl.SSLException: hostname in certificate didn't match: <revue.co.in> != <*.prod.sin2.secureserver.net> OR <*.prod.sin2.secureserver.net> OR <prod.sin2.secureserver.net>
03-16 23:11:59.487 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:190)
03-16 23:11:59.487 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:59)
03-16 23:11:59.487 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:119)
03-16 23:11:59.487 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:100)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:393)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:170)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:379)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:580)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:503)
03-16 23:11:59.488 20262-20480/com.revu.revu W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:481)
&#13;
以上错误表示SSL问题。如何在android中允许客户端和服务器之间的 https 通信。