at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:267)
时间: 2024-05-25 14:12:43 浏览: 7
这个错误提示是在 OkHttp 框架中出现的,它通常表示在建立 TLS 安全连接时出现了问题。具体原因可能是 TLS 握手失败、证书无效等等。建议检查你的网络连接是否正常、证书是否正确,并且确保服务器端和客户端 TLS 版本一致。你可以尝试打开 OkHttp 的调试模式,查看详细的错误信息,以便更好地定位问题。
相关问题
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.bawei.xuhe, PID: 22989 java.net.UnknownServiceException: CLEARTEXT communication to 10.59.9.18 not permitted by network security policy at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:188) at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226) at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106) at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74) at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:221) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) at retrofit2.OkHttpCall.execute(OkHttpCall.java:204) at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41) at io.reactivex.Observable.subscribe(Observable.java:10179) at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34) at io.reactivex.Observable.subscribe(Observable.java:10179) at io.reactivex.internal.operators.observable.ObservableSubscribeOn$1.run(ObservableSubscribeOn.java:39) at io.reactivex.Scheduler$1.run(Scheduler.java:134) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:59) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:51) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) I/Process: Sending signal. PID: 22989 SIG: 9
这一个 Android 运行时错误,指示您的应用程序尝试使用不安全的明文通信与 IP 地址为 10.59.9.18 的服务器进行交互,但是 Android 的网络安全策略禁止了此类操作。
为了解决此问题,您可以尝试以下几种方法:
1. 使用 HTTPS 协议替代明文通信。
2. 在 AndroidManifest.xml 文件中添加以下代码,以允许您的应用程序使用不安全的明文通信:
```
<application
...
android:usesCleartextTraffic="true">
...
</application>
```
3. 在您的网络请求中使用 Android 网络安全配置,以允许特定的 IP 地址使用明文通信,例如:
```
<network-security-config>
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="@raw/my_ca"/>
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.59.9.18</domain>
</domain-config>
</network-security-config>
```
请注意,这些解决方案中的某些选项可能会影响您应用程序的安全性,请谨慎选择。
Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.Socket.connect(Socket.java:607) at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129) at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:246) ... 52 common frames omitted
这个错误通常表示你的 Java 应用程序无法连接到目标主机。可能的原因包括:
1. 目标主机未启动或未监听指定端口;
2. 防火墙或其他网络设备阻止了连接;
3. 应用程序正在尝试连接到错误的 IP 地址或端口;
4. 目标主机上的服务已停止或崩溃。
要解决这个问题,你可以尝试以下步骤:
1. 确保目标主机正在运行,并且已启动你要连接的服务;
2. 检查防火墙或其他网络设备是否允许连接到目标主机的指定端口;
3. 确认应用程序正在连接到正确的 IP 地址和端口;
4. 检查目标主机上的服务是否正在运行,并且没有崩溃。
如果仍然无法解决问题,你可以尝试使用 telnet 命令测试连接,或者检查应用程序日志以获取更详细的错误信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)