我们正在尝试与“HttpsURLConnection”对象进行服务器通信,我们已将请求对象的“connection”属性设置为“关闭”[setRequestProperty("Connection", "关闭")]。上述设置在所有设备的 Android 9 操作系统中都运行良好,但在某些使用 Android 10 操作系统的设备(例如:配备 Android 10 的三星 A70)中,我们遇到了 "java.net.ConnectException”。当我们删除连接属性后,服务器通信就建立起来并解决了问题。我需要您的支持来了解 Android 10 操作系统中行为发生变化的根本原因以及删除连接对象是否会产生任何影响
url = new URL(reqURL);
httpsConnection = url.openConnection();
httpsConnection.setRequestMethod("POST");
httpsConnection.setRequestProperty("Content-Language", "en");
httpsConnection.setRequestProperty("Connection", "close");
httpsConnection.setRequestProperty("Content-Type","application/text");
OutputStream os = httpsConnection.getOutputStream();
os.write(cvmesgToServer.getBytes()) httpsConnection.connect();
最佳答案
您需要设置超时 - 三星更新有问题
关于android - Android 10 中的服务器连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61187285/