Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit @GET - how to display request string?

Tags:

I'm working on an Android application that uses Retrofit to create a restful client. In order to debug networks calls, I would like to display or dump the url that's actually being invoked. Is there a way to do this? I've included some code below which shows how the app currently using retrofit.

Client interface definition:

import retrofit.Callback; import retrofit.http.Body; import retrofit.http.GET; import retrofit.http.Headers; import retrofit.http.POST; import retrofit.http.Path;  // etc...   public interface MyApiClient {      @Headers({             "Connection: close"     })      @GET("/{userId}/{itemId}/getCost.do")     public void get(@Path("userId") String userId, @Path("itemId") String userId, Callback<Score> callback);   //....etc   } 

Service which uses generated client:

// etc...     import javax.inject.Inject;     import retrofit.Callback;     import retrofit.RetrofitError;     import retrofit.client.Response;   @Inject MyApiClient myApiClient;  // etc...                myApiClient.getCost(myId, itemId, new Callback<Cost>() {                      @Override                     public void success(Cost cost, Response response) {                         Log.d("Success: %s", String.valueOf(cost.cost));                         if (cost.cost != -1) {                             processFoundCost(cost);                         } else {                             processMissingCost(itemId);                         }                         stopTask();                     }                      @Override                     public void failure(RetrofitError error) {                         handleFailure(new CostFailedEvent(), null);                     }                 });             } 
like image 754
Jack BeNimble Avatar asked May 06 '15 19:05

Jack BeNimble


People also ask

How do I know if a URL is retrofit?

one of the attributes you can assign to Retrofit builder is the client, set the client to the client from the first function. After running this code you could search for OkHttp tag in the logcat and you will see the requests and responses you made.


1 Answers

call.request().url(), where call is type of retrofit2.Call.

like image 199
Aragats Amirkhanyan Avatar answered Sep 20 '22 20:09

Aragats Amirkhanyan