android https no peer certificate,Android SSL - No Peer Certificate

Whenever this code runs, I get a 'No Peer Certificate' error.

SSL certificate is valid, bought from Namecheap (PositiveSSL). It has the CA crt before it, and opens fine in the Android browser.

HTTP server: nginx

Code:

public void postData() {

// Add your data

List nameValuePairs = new ArrayList(2);

nameValuePairs.add(new BasicNameValuePair("string", "myfirststring"));

try {

HttpPost post = new HttpPost(new URI("https://example.com/submit"));

post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

KeyStore trusted = KeyStore.getInstance("BKS");

trusted.load(null, "".toCharArray());

SSLSocketFactory sslf = new SSLSocketFactory(trusted);

sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

SchemeRegistry schemeRegistry = new SchemeRegistry();

schemeRegistry.register(new Scheme ("https", sslf, 443));

SingleClientConnManager cm = new SingleClientConnManager(post.getParams(),

schemeRegistry);

HttpClient client = new DefaultHttpClient(cm, post.getParams());

// Execute HTTP Post Request

@SuppressWarnings("unused")

HttpResponse result = client.execute(post);

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

} catch (URISyntaxException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

} catch (KeyStoreException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

} catch (NoSuchAlgorithmException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

} catch (CertificateException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Log.e(TAG,e.toString());

Log.e(TAG,e.getMessage());

} catch (KeyManagementException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

} catch (UnrecoverableKeyException e) {

// TODO Auto-generated catch block

Log.e(TAG,e.getMessage());

Log.e(TAG,e.toString());

e.printStackTrace();

}

}

Adb logcat:

01-10 15:44:34.872: E/myfirstapp(572): No peer certificate

01-10 15:44:34.872: E/myfirstapp(572): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

01-10 15:44:34.883: W/System.err(572): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

01-10 15:44:34.883: W/System.err(572): at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)

01-10 15:44:34.883: W/System.err(572): at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)

01-10 15:44:34.908: W/System.err(572): at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)

01-10 15:44:34.908: W/System.err(572): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)

01-10 15:44:34.908: W/System.err(572): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)

01-10 15:44:34.914: W/System.err(572): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)

01-10 15:44:34.914: W/System.err(572): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)

01-10 15:44:34.914: W/System.err(572): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)

01-10 15:44:34.914: W/System.err(572): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)

01-10 15:44:34.914: W/System.err(572): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

01-10 15:44:34.933: W/System.err(572): at com.giggsey.myfirstapp.myfirstappIntent.postData(myfirstappIntent.java:126)

01-10 15:44:34.933: W/System.err(572): at com.giggsey.myfirstapp.myfirstappIntent.onReceive(myfirstappIntent.java:77)

01-10 15:44:34.933: W/System.err(572): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2118)

01-10 15:44:34.945: W/System.err(572): at android.app.ActivityThread.access$1500(ActivityThread.java:122)

01-10 15:44:34.945: W/System.err(572): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

01-10 15:44:34.952: W/System.err(572): at android.os.Handler.dispatchMessage(Handler.java:99)

01-10 15:44:34.952: W/System.err(572): at android.os.Looper.loop(Looper.java:137)

01-10 15:44:34.962: W/System.err(572): at android.app.ActivityThread.main(ActivityThread.java:4340)

01-10 15:44:34.962: W/System.err(572): at java.lang.reflect.Method.invokeNative(Native Method)

01-10 15:44:34.962: W/System.err(572): at java.lang.reflect.Method.invoke(Method.java:511)

01-10 15:44:34.972: W/System.err(572): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

01-10 15:44:34.972: W/System.err(572): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

01-10 15:44:34.981: W/System.err(572): at dalvik.system.NativeStart.main(Native Method)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值