gpt4 book ai didi

android - 在 Android 中使用 HttpsURLConnection 的 SSLHandshakeException

转载 作者:行者123 更新时间:2023-11-29 17:20:50 25 4
gpt4 key购买 nike

关于我的应用的详细信息:

compileSdkVersion 22
buildToolsVersion '22.0.1'



defaultConfig {
applicationId "My application id"
minSdkVersion 13
targetSdkVersion 22
versionCode 4
versionName "2"
}

我正在使用 HttpsURLConnection 进行登录身份验证。但现在我正面临 javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException 在运行在 android lollipop.Authentication 下的设备上在运行操作系统版本 5 以上的设备上按预期工作。请让我知道您对此问题的建议。

这是我正在使用的代码:

    HttpsURLConnection conn = null;
try {
URL url = new URL("URL to my application");

String authStr = username + ":" + password;

String authEncoded = Base64.encodeToString(authStr.getBytes(), Base64.NO_WRAP);
conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Basic " + authEncoded);
conn.setDoOutput(true);

conn.setConnectTimeout(120000);
int code = conn.getResponseCode();

if(code ==200){
for(int i=0;i<conn.getHeaderFields().size();i++){
String value = conn.getHeaderField(i);

HeaderElement headerElement = BasicHeaderValueParser.parseHeaderElement(value, new BasicHeaderValueParser());

if(headerElement.getName().equals("SMSESSION")){

cookieString = SMSESSION+"="+headerElement.getValue();
Log.d("validhdvaluelogin",cookieString);
cookieeditor.putString(ArticleListActivity.CURRENT_COOKIE,
cookieString);
cookieeditor.apply();

return true;
}


}
}else {
return false;
}



}

catch (Exception e) {
e.printStackTrace();
return false;
}


if (conn != null) {
conn.disconnect();
}

return false;

这里是异常(exception):

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL       
handshake aborted: ssl=0xb87b0350: Failure in SSL library, usually a
protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake
failure (external/openssl/ssl/s23_clnt.c:741 0xa9092990:0x00000000)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:448)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:661)
at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:632)
at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:70)
at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:172)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.ericsson.labs.it.infoservicemx.network.AuthComm.login(AuthComm.java:148)
at com.ericsson.labs.it.infoservicemx.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:312)
at com.ericsson.labs.it.infoservicemx.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:230)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb87b0350: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0xa9092990:0x00000000)
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405)
... 23 more

最佳答案

我终于找到了解决问题的方法。通过使用 NetCipher 库进行 httpsurl 连接。而不是使用:

HttpsUrlConnection conn = (HttpsURLConnection) url.openConnection();

使用:

HttpsUrlConnection conn =  NetCipher.getHttpsURLConnection(url);

这解决了我的 SSLv3 握手问题。

关于android - 在 Android 中使用 HttpsURLConnection 的 SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36619889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com