简体   繁体   中英

Cannot connect to local webserver in app, but adb shell works

I have a system service on my android phone which runs a webserver as soon as the device is booted. When I go into the adb shell and use curl to make a request it works perfectly fine, but as soon as I try to do it within any android app running on the same device I get an error saying that it failed to connect:

Caused by: java.net.SocketTimeoutException: failed to connect to /127.0.0.1 (port 8545) from /127.0.0.1 (port 48102) after 10000ms

and this is for reference my curl command (this works):

curl http://127.0.0.1:8545

WebView honors clear text traffic for applications targeting API level 26 and higher.

The application you are using to access your service (which you didn't mention) should have the attribute android:usesCleartextTraffic set to true .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM