最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - HTTP FAILED: java.net.ConnectException: Failed to connect to 127.0.0.1:8000 - Stack Overflow

programmeradmin5浏览0评论

I am developing an android app in Kotlin and trying to make a request to my local Django server but getting this error.

The local server is launched on IP and port 127.0.0.1:8000 and I specified in my android application the base url - http://127.0.0.1:8000/api, but I getting this error.

I tried running it on both an emulator and a physical Android device, but I get the same result in both cases.

I checked similar questions on StackOverflow and they suggest the following solutions:

  1. Find out the IP-address and enter it in the link, I found out my IP-address (for example 192.168.0.102) and used it instead of 127.0.0.1.
  2. Start local server via 0.0.0.0:8000.
  3. Add to ALLOWED_HOSTS IP-address of your PC in setting.py.
  4. Use IP address 10.0.2.2 for android emulator.
  5. If you have a Firewall active, add an exception for port 8000. Even though I have Firewall disabled, I still added an exception for port 8000.
  6. Started the server via IP address 192.168.0.102:8000.

But when I tried all this, I got the following result:

1.

<-- HTTP FAILED: java.ConnectException: Failed to connect to /192.168.0.102:80

  1. Same result as number 1.

  2. Same result as number 1.

<-- HTTP FAILED: java.ConnectException: Failed to connect to /10.0.0.2:8000

<-- HTTP FAILED: java.ConnectException: Failed to connect to /10.0.0.2:80

  1. Same result as number 1.

<-- 400 Bad Request http://192.168.1.102:8000/api/register/ (284ms)

if you go to this url: http://192.168.1.212:8000/api/register/

My PC and my Android device are connected to the same Wi-Fi and I use the IP-address of my PC instead of 127.0.0.1:8000, but it gives what is indicated in the screenshot above and in point 6.

But http://127.0.0.1:8000 opens the page in the browser on my PC, but on the Android device it does not work.

发布评论

评论列表(0)

  1. 暂无评论