0

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());
                }
            }
    );
2
  • your emulator has different network from you machine, stackoverflow.com/questions/5528850/… Commented Jul 18, 2020 at 16:23
  • I am using my phone via USB. How to fix this? Commented Jul 19, 2020 at 6:56

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.