OkHttp无法连接到ESP8266

问题描述 投票:0回答:1

我正在尝试从Android手机向ESP8266发送简单的HTTP请求。我正在关注this教程。该代码适用于教程中使用的URL(https://reqres.in/api/users?page=2),但不适用于使ESP8266上的LED点亮的URL。 (尽管可以通过浏览器打开LED,所以代码一定是这样)。 URL是https://192.168.137.78/led/1。stacktrace很长,但这是第一个错误,

2020-06-13 12:55:55.948 13594-13631/com.example.esp W/System.err: java.net.ConnectException: Failed to connect to /192.168.137.78:443

其余堆栈跟踪:

2020-06-13 12:55:55.948 13594-13631/com.example.esp W/System.err: java.net.ConnectException: Failed to connect to /192.168.137.78:443
    2020-06-13 12:55:55.949 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:285)
    2020-06-13 12:55:55.949 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:195)
    2020-06-13 12:55:55.950 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:249)
    2020-06-13 12:55:55.950 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:108)
    2020-06-13 12:55:55.950 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:76)
    2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:245)
    2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
    2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
    2020-06-13 12:55:55.951 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:96)
    2020-06-13 12:55:55.952 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
    2020-06-13 12:55:55.952 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
    2020-06-13 12:55:55.952 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
    2020-06-13 12:55:55.953 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
    2020-06-13 12:55:55.953 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
    2020-06-13 12:55:55.953 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
    2020-06-13 12:55:55.954 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:502)
    2020-06-13 12:55:55.954 13594-13631/com.example.esp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    2020-06-13 12:55:55.954 13594-13631/com.example.esp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    2020-06-13 12:55:55.955 13594-13631/com.example.esp W/System.err:     at java.lang.Thread.run(Thread.java:919)
    2020-06-13 12:55:55.956 13594-13631/com.example.esp W/System.err: Caused by: java.net.ConnectException: failed to connect to /192.168.137.78 (port 443) from /192.168.137.82 (port 42408) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
    2020-06-13 12:55:55.956 13594-13631/com.example.esp W/System.err:     at libcore.io.IoBridge.isConnected(IoBridge.java:288)
    2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err:     at libcore.io.IoBridge.connectErrno(IoBridge.java:193)
    2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:135)
    2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err:     at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
    2020-06-13 12:55:55.957 13594-13631/com.example.esp W/System.err:     at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
    2020-06-13 12:55:55.958 13594-13631/com.example.esp W/System.err:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
    2020-06-13 12:55:55.958 13594-13631/com.example.esp W/System.err:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
    2020-06-13 12:55:55.959 13594-13631/com.example.esp W/System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
    2020-06-13 12:55:55.959 13594-13631/com.example.esp W/System.err:     at java.net.Socket.connect(Socket.java:621)
    2020-06-13 12:55:55.959 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:120)
    2020-06-13 12:55:55.960 13594-13631/com.example.esp W/System.err:     at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:283)
    2020-06-13 12:55:55.960 13594-13631/com.example.esp W/System.err:   ... 18 more
    2020-06-13 12:55:55.961 13594-13631/com.example.esp W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
    2020-06-13 12:55:55.961 13594-13631/com.example.esp W/System.err:     at libcore.io.IoBridge.isConnected(IoBridge.java:275)
    2020-06-13 12:55:55.961 13594-13631/com.example.esp W/System.err:   ... 28 more
android embedded iot okhttp esp8266
1个回答
0
投票

您正在发送HTTPS请求,而不是HTTP请求。您尚未共享在ESP8266上运行的代码,但我敢打赌,它是HTTP服务器,而不是HTTPS服务器。将您尝试连接的URL更改为http://,而不是https://

© www.soinside.com 2019 - 2024. All rights reserved.