1、因为请求的接口是https,开始以为是证书的原因,但是在模拟器和别的手机上没有发现这个问题,后来Google搜了一下,发现是魅蓝note手机本地时间的原因
解决
联网校验手机本地时间即可
2、OKhttp3 添加安全认证
/**
* okhttp HTTPS安全认证
* Okhttp3 Could not validate certificate: null
*
* @return
*/
private static SSLSocketFactorygetSSLSocketFactory() {
final TrustManager[] trustAllCerts =new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {
}
@Override
public X509Certificate[]getAcceptedIssuers() {
return new X509Certificate[0];
}
}
};
SSLContext sslContext =null;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
}catch (KeyManagementException e) {
e.printStackTrace();
}catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return sslSocketFactory;
}
网友评论