【发布时间】:2020-04-13 11:51:28
【问题描述】:
我们正在尝试与 "HttpsURLConnection" 对象进行服务器通信,其中我们已将请求对象的 "connection" 属性设置为 "close" [setRequestProperty("Connection", "关闭")]。上述设置在所有设备的 Android 9 操作系统中运行良好,而在某些具有 Android 10 操作系统的设备中(例如:带有 Android 10 的三星 A70)我们遇到了 " java.net.ConnectException”。当我们删除 Connection 属性时,服务器通信建立并解决了问题。我需要您的支持来了解 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();
【问题讨论】:
-
你能贴出相关代码和stacktrace吗
-
您还没有告诉关闭请求的作用。或者你为什么需要它。
标签: android connection android-10.0 httpsurlconnection