Saransh Khurana
Saransh Khurana

Reputation: 59

connecting django devserver from android studio fails

I am trying to connect to django rest framework server from android studio on my local machine using volley . I tried running server with 0.0.0.0:8000 on command line and have added ALLOWED_HOST=[*] in settings.py.

Error message in android studio

com.android.volley.NoConnectionError: java.net.ConnectException: Failed to connect to /0.0.0.0:8000

Below is the android client code

P.S:- All the import libraries are included.

 String URL= "http://0.0.0.0:8000/api/userdata/";
 RequestQueue requestQueue = Volley.newRequestQueue(this);
 JsonObjectRequest objectRequest = new JsonObjectRequest(
            Request.Method.GET,
            URL,
            null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("Response:",response.toString());

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Response:",error.toString());
                }
            }
    );

Upvotes: 0

Views: 230

Answers (2)

abtinmo
abtinmo

Reputation: 366

use ifconfig or ipconfig to find your local IP, and call your server with that

Upvotes: 1

Saransh Khurana
Saransh Khurana

Reputation: 59

I tried using a deployed API from open weather. It works perfectly fine. The problem was I was trying to access django REST Api from development server.

Upvotes: 0

Related Questions