gpt4 book ai didi

java - Android 上不一致的 SSLv3 握手失败

转载 作者:太空宇宙 更新时间:2023-11-03 12:49:29 24 4
gpt4 key购买 nike

我正在开发一个处理食品订单的应用程序,我们通过 HttpsURLConnection 将请求发送到已通过 ssl 认证的 php 函数。我遇到的问题是它有时会拒绝握手,而其他人则不会。我想知道是否有人可以向我解释为什么它会拒绝一次而不是另一次。

javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x56cbe008: 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:744 0x52eb6d74:0x00000000) javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x56cbe008: 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:744 0x52eb6d74:0x00000000)

url = new URL(request.endpointUri);

Log.d(LOG_TAG, "Opening connection to " + request.endpointUri);
conn = (HttpsURLConnection)url.openConnection();

//setup the connection
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "UTF-8");
conn.setDoInput(true);
conn.setDoOutput(true);

//setup the parameters
Uri.Builder params = new Uri.Builder();
String paramString;

params.appendQueryParameter("cctoken", request.token.getId());
params.appendQueryParameter("amt", Integer.toString(request.order.amount));
params.appendQueryParameter("email", request.order.customerEmail);
params.appendQueryParameter("order", request.order.details);

paramString = params.build().getEncodedQuery();
conn.setFixedLengthStreamingMode(paramString.getBytes("UTF-8").length);

Log.d(LOG_TAG, "Compiled query into: " + paramString);

//write the POST request params
OutputStream os = conn.getOutputStream();
BufferedWriter streamWriter = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
streamWriter.write(paramString);
streamWriter.flush();
streamWriter.close();
os.close();

//read the response
int responseCode = conn.getResponseCode();
InputStream is;

失败的行是在它尝试收集输出时。

OutputStream os = conn.getOutputStream();

最佳答案

有时只发生的 SSL 握手错误通常与服务器端问题有关,因此您的代码在这里没有太大帮助。服务器端的可能原因是多个服务器具有不同的配置(一些工作,一些不工作),可能由负载过大引起的超时,服务器端崩溃。可能还涉及一些不稳定的中间件(防火墙),或者如果连接从一开始就不可靠,它也会影响 SSL 握手。

因此不要过多地查看您的代码,而是查看服务器和网络。如果有疑问,请尝试另一个客户端,如果这个客户端表现出更稳定的行为,请查看连接和 SSL 握手(即数据包捕获)中的差异。

关于java - Android 上不一致的 SSLv3 握手失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34597919/

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