如何解决 javax.net.ssl.SSLPeerUnverifiedException: Hostname .com not verified:
how to solve javax.net.ssl.SSLPeerUnverifiedException: Hostname .com not verified:
我有以下错误 Hostname domain.com not verified:
不是 "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated"
我之前能够连接到不同的主机,在这个主机上我遇到了问题,如何修复它
javax.net.ssl.SSLPeerUnverifiedException: Hostname domain.com not verified:
certificate: sha1//WQM9QbrKs6DCFa9qN/EIw1ywBw=
DN: CN=*.ipage.com,OU=Domain Control Validated - RapidSSL(R),OU=See www.rapidssl.com/resources/cps (c)14,OU=GT29505539
subjectAltNames: [*.ipage.com, ipage.com]
at com.squareup.okhttp.Connection.connectTls(Connection.java:244)
at com.squareup.okhttp.Connection.connectSocket(Connection.java:199)
at com.squareup.okhttp.Connection.connect(Connection.java:172)
at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
at com.squareup.okhttp.OkHttpClient.connectAndSetOwner(OkHttpClient.java:128)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
at com.squareup.okhttp.Call.getResponse(Call.java:267)
这是我的代码
try {
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", name);
jsonObject.accumulate("password", pass);
jsonObject.accumulate("email", emails);
json = jsonObject.toString();
Log.e("MYAPP", "getjson");
} catch (JSONException e) {
Log.e("MYAPP", "unexpected JSON exception", e);
}
try{
RequestBody formBody = new FormEncodingBuilder()
.add("name", name)
.build();
Request request = new Request.Builder()
.url("https://justedhak.com/Files/users.php")
.post(formBody)
.build();
更新
因为例外是 javax.net.ssl.SSLPeerUnverifiedException: Hostname justedhak.com not verified
,DN: CN=*.ipage.com...
和 subjectAltNames: [*.ipage.com, ipage.com]
因此,您可以将我下面示例代码中的 setHostnameVerifier
替换为以下内容(因为不推荐使用 return true
):
client.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
//return true;
HostnameVerifier hv =
HttpsURLConnection.getDefaultHostnameVerifier();
return hv.verify("ipage.com", session);
}
});
你也会得到如下截图的成功结果。
如果您只想使用该主机的 HTTPS
作为您的 学习 目的或 开发 环境,您可以参考下面的方法,当然你可以把我的GET
请求改成你的POST
一个:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.textView);
mHandler = new Handler(Looper.getMainLooper());
OkHttpClient client = new OkHttpClient();
client.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
Request request = new Request.Builder()
.url("https://justedhak.com/Files/users.php")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
// do something...
Log.e(LOG_TAG, e.toString());
}
@Override
public void onResponse(Response response) throws IOException {
// do something...
Log.i(LOG_TAG, response.body().string());
}
});
}
这是屏幕截图
您还可以在以下问题中阅读更多内容:
我在 Jenkins 尝试访问 GIT 时遇到了同样的错误,真正的错误是 GIT 地址定期更改(基于 AWS)并且 Jenkins 的地址是 GIT ,这不再有效。重启 jvm 就可以解决,但是减少 ttl 是最好的解决方案
我有以下错误 Hostname domain.com not verified:
不是 "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated"
我之前能够连接到不同的主机,在这个主机上我遇到了问题,如何修复它
javax.net.ssl.SSLPeerUnverifiedException: Hostname domain.com not verified:
certificate: sha1//WQM9QbrKs6DCFa9qN/EIw1ywBw=
DN: CN=*.ipage.com,OU=Domain Control Validated - RapidSSL(R),OU=See www.rapidssl.com/resources/cps (c)14,OU=GT29505539
subjectAltNames: [*.ipage.com, ipage.com]
at com.squareup.okhttp.Connection.connectTls(Connection.java:244)
at com.squareup.okhttp.Connection.connectSocket(Connection.java:199)
at com.squareup.okhttp.Connection.connect(Connection.java:172)
at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
at com.squareup.okhttp.OkHttpClient.connectAndSetOwner(OkHttpClient.java:128)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
at com.squareup.okhttp.Call.getResponse(Call.java:267)
这是我的代码
try {
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", name);
jsonObject.accumulate("password", pass);
jsonObject.accumulate("email", emails);
json = jsonObject.toString();
Log.e("MYAPP", "getjson");
} catch (JSONException e) {
Log.e("MYAPP", "unexpected JSON exception", e);
}
try{
RequestBody formBody = new FormEncodingBuilder()
.add("name", name)
.build();
Request request = new Request.Builder()
.url("https://justedhak.com/Files/users.php")
.post(formBody)
.build();
更新
因为例外是 javax.net.ssl.SSLPeerUnverifiedException: Hostname justedhak.com not verified
,DN: CN=*.ipage.com...
和 subjectAltNames: [*.ipage.com, ipage.com]
因此,您可以将我下面示例代码中的 setHostnameVerifier
替换为以下内容(因为不推荐使用 return true
):
client.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
//return true;
HostnameVerifier hv =
HttpsURLConnection.getDefaultHostnameVerifier();
return hv.verify("ipage.com", session);
}
});
你也会得到如下截图的成功结果。
如果您只想使用该主机的 HTTPS
作为您的 学习 目的或 开发 环境,您可以参考下面的方法,当然你可以把我的GET
请求改成你的POST
一个:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.textView);
mHandler = new Handler(Looper.getMainLooper());
OkHttpClient client = new OkHttpClient();
client.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
Request request = new Request.Builder()
.url("https://justedhak.com/Files/users.php")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
// do something...
Log.e(LOG_TAG, e.toString());
}
@Override
public void onResponse(Response response) throws IOException {
// do something...
Log.i(LOG_TAG, response.body().string());
}
});
}
这是屏幕截图
您还可以在以下问题中阅读更多内容:
我在 Jenkins 尝试访问 GIT 时遇到了同样的错误,真正的错误是 GIT 地址定期更改(基于 AWS)并且 Jenkins 的地址是 GIT ,这不再有效。重启 jvm 就可以解决,但是减少 ttl 是最好的解决方案