我正在使用一个使用Retrofit创建一个休息的客户端的
Android应用程序.为了调试网络调用,我想显示或转储实际被调用的url.有没有办法做到这一点?我已经在下面列出了一些代码,显示了应用程序当前如何使用改进.
客户端界面定义:
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 callback);
//....etc
}
使用生成客户端的服务:
// 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() {
@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);
}
});
}