我的应用适用于许多国家/地区。但是,几乎没有国家 哪个应用程序不起作用。它提供SSL握手异常和超时 例外。这种情况仅发生在沙特阿拉伯等少数国家, 巴林,梵蒂冈等地。
W/System.err: javax.net.ssl.SSLException: Connection closed by peer
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406)
W/System.err: at com.android.okhttp.Connection.upgradeToTls(Connection.java:146)
W/System.err: at com.android.okhttp.Connection.connect(Connection.java:107)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)
我的Java Api客户端代码
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(request.getRequestType());
if (request.getHeaders() != null) {
Boolean usApkTest = mSharedPreferencesManager.getUsApkTest();
if (usApkTest) {
request.getHeaders().put("COUNTRY", "US");
}
setConnectionHeaders(connection, request.getHeaders());
}
if (request.getBody() != null) {
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
JSONObject body;
body = new JSONObject(request.getBody());
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(body.toString());
wr.close();
} else if (request.getBodyJson() != null) {
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(request.getBodyJson().toString());
wr.close();
}
connection.setReadTimeout(request.getRequestTimeout());
connection.connect();
responseCode = connection.getResponseCode();
Logger.v("RESPONSE CODE", "RESPONSE CODE: " + responseCode);
stringBuilder = new StringBuilder();
String line = null;
if (responseCode == 401 || responseCode == 422 || responseCode == 404 || responseCode == 403) {
if (connection.getErrorStream() != null)
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
} else
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = reader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
有谁知道为什么会这样。
我也遇到了一个链接 https://www.reddit.com/r/Android/comments/p0y97/it_sucks_to_be_an_android_user_in_saudi_arabia/ 这对我的问题有用吗?