Skip to content Skip to sidebar Skip to footer

How To Do A Get Request Using Retrofit2?

I have a restfull web service which is running on a localhost. I would like to make a retrofit2 GET request on that rest URL. MainActivity.java private void requestData() {

Solution 1:

Your baseurl contains /users in the end.It should be removed as it will be received by the app from the inerface @GET("/users") Your baseUrl should be

publicstaticfinalStringBASE_URL="http://192.168.0.103:8080/SpringWithHibernate/"

and in interface

publicinterfaceGetUserListAPI {
    @GET("users")
    Call<List<UserPojo>> getUsersList();
}

Solution 2:

If you are getting 404 error its not associated with the retrofit, its backend issue. Is that webservice is currently active one? But i found another issue in your request, which is that

publicstaticfinalStringBASE_URL="http://192.168.0.103:8080/SpringWithHibernate/users/";

and in Retrofit interface you have declared

@GET("/users")

So the combined URL will result in

http://192.168.0.103:8080/SpringWithHibernate/users/users

Which is not correct, you should only declare your base url in the string and service names in retrofit interface methods.

Post a Comment for "How To Do A Get Request Using Retrofit2?"