2

I have written a Retrofit code which has a Yii2 backend. The problem is: when I call the web-service on backend, it works perfectly. However, when I try to call the web-service from android device; it throws a response code of 404. Here is what I have done:

I am targeting a url which looks like: http://192.168.0.104/root-web/web/index.php?r= and it had an end-point: root/register

public interface RegisterAPIService {
    @POST("practice/register")
    Call<RegisterModel> registerUser(@Body RegisterDetails registerDetails);
}

The code in my activity looks like this..

            RegisterDetails registerDetails = new RegisterDetails(email, mobile, password);

            RegisterAPIService registerAPIService = retrofit.create(RegisterAPIService.class);

            Call<RegisterModel> call =registerAPIService.registerUser(registerDetails);

            call.enqueue(new Callback<RegisterModel>() {
                @Override
                public void onResponse(Response<RegisterModel> response) {

                    Log.d("Message", "code..."+response.code() + " message..." + response.message()+" body..."+response.body());
                }

                @Override
                public void onFailure(Throwable t) {

                }
            });
        } else {
             // Error
        }
    }

I am getting 404 for the above code. I am trying to send my parameters in the form of a POST request. Please guide me through it.

Nevermore
  • 882
  • 2
  • 18
  • 44

1 Answers1

0

You should call your development machine from the device, by its ip address, based on how they are connected. Also you can use Android Reverse Tethering tools for your operating system. for further study and options you can take a look at the answers to this question

Community
  • 1
  • 1
Farhad
  • 12,178
  • 5
  • 32
  • 60
  • can you call the url , from the web browser of your android device, successfully ? – Farhad Nov 18 '15 at 12:39
  • I think you are missing the port number. On what port is your web service available for external client ? if you've not configured it, it may be 80, or 8080 – Farhad Nov 18 '15 at 12:40
  • It is showing on the android device's browser correctly. The error response. The default port is being used is 80 – Nevermore Nov 18 '15 at 12:43
  • Is it due to the wrong Yii url format that I have..? – Nevermore Nov 18 '15 at 12:47
  • I'm thinking of the same...paste the exact url that you call from the browser once more – Farhad Nov 18 '15 at 12:48
  • The base url that I have is http://192.168.0.104/root-web/web/index.php?r= And the endpoint I have is like: @POST("practice/register") Should I combine them as base url and keep my endpoint as empty..? – Nevermore Nov 18 '15 at 12:50