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

javax.net.ssl.SSLProtocolException:SSL握手已中止:
ssl = 0x56cbe008:SSL库失败,通常是协议错误
错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败(外部/openssl/ssl/s23_clnt.c:744
0x52eb6d74:0x00000000)
javax.net.ssl.SSLHandshakeException:javax.net.ssl.SSLProtocolException:SSL握手已中止:
ssl = 0x56cbe008:SSL库失败,通常是协议错误
错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败(外部/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握手(即数据包捕获)之间的差异。

07-28 02:33
查看更多