lp_nave
lp_nave

Reputation: 404

Sending Api requests from Android to Localhost

Im trying to get my android app in my phone to talk with the spring boot backend. I tried setting the ip address of my pc instead of using it as the "localhost". but it does not work though. Any idea on how to fix this and get by application to sent requests to my spring boot backend?

This is my code for the api call and the client.getProxy() will retrieve the saved "http://......" (PS: im using the volley library)

  JsonObjectRequest authenticate = new JsonObjectRequest(
            Request.Method.POST, client.getProxy() + "/authenticate", auth,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    resp = response.toString();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            resp= "FAILED ";
        }
    }

Thanks in advance.

Upvotes: 0

Views: 566

Answers (1)

moon
moon

Reputation: 333

Instruction for the local host to physical mobile. your mobile and laptop must be connected on same WiFi. Then you need to set your laptop ip on link from the command prompt.command ipconfig and get ipv4address from the result

Upvotes: 1

Related Questions