我有.crt和.ca文件。我尝试粘贴到res / raw文件,并从socket.io创建一个套接字。用于https的目的。如果从空项目android studio开始,我该怎么办?
答案 0 :(得分:0)
我自己解决了这个问题:
并且:
HostnameVerifier myHostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
HostnameVerifier hv =
HttpsURLConnection.getDefaultHostnameVerifier();
return hv.verify("example.com", session);
}
};
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.hostnameVerifier(myHostnameVerifier)
.sslSocketFactory(mySSLContext.getSocketFactory(), myX509TrustManager)
.build();
// default settings for all sockets
IO.setDefaultOkHttpWebSocketFactory(okHttpClient);
IO.setDefaultOkHttpCallFactory(okHttpClient);
// set as an option
opts = new IO.Options();
opts.callFactory = okHttpClient;
opts.webSocketFactory = okHttpClient;
socket = IO.socket("https://example.com", opts);
context.init(null,tmf.getTrustManagers(),null);
下面的connect()内部
并且{coin InputStream caInput = getAssets().open("yourca.crt");
与未自签名的ssl。而已。希望它能使这个论坛更好,这太冷了!