Cannot connect to localhost API from Android app

前端 未结 8 2189
星月不相逢
星月不相逢 2020-12-10 06:47

I am new to Django. I have created an API named http://127.0.0.1:8000/api/update/1/ and it works perfectly in the browser and on the Postman app.

Howev

8条回答
  •  感情败类
    2020-12-10 07:38

    Please run your django development server using the following command.

    python manage.py runserver 0.0.0.0:8000
    

    Once you get it running, in a new terminal window find out the ip address of your computer in your wifi/network subnet using the following command

    Ipconfig or ifconfig (depends on your OS)
    

    Then change the base url of your api from 127.0.0.1 to the ip you found in the above step. Now connect the android phone in which your app is being tested to your same wifi or network to which the computer running django is connected. Now you can request and receive response.

    127.0.0.1 is the home of your system, your android app will not be able to access that. You need to do it like this.

提交回复
热议问题