改造2检查呼叫URL

Gio*_*oli 9 android http retrofit retrofit2

是否有可能将CallURL与Stringin 进行比较Retrofit 2

例如,我们可以这样做baseUrl:

https://www.google.com
Run Code Online (Sandbox Code Playgroud)

这个Call:

public interface ExampleService {
    @GET("dummy/{examplePartialUrl}/")
    Call<JsonObject> exampleList(@Path("examplePartialUrl") String examplePartialUrl;
}
Run Code Online (Sandbox Code Playgroud)

有这个要求:

Call<JsonObject> mCall = dummyService.exampleList("partialDummy")
Run Code Online (Sandbox Code Playgroud)

有没有办法获得https://www.google.com/dummy/partialDummydummy/partialDummy在获得通话响应之前?

tre*_*r-e 21

假设您正在使用OkHttp和Retrofit,您可以执行以下操作:

dummyService.exampleList("partialDummy").request().url().toString()

根据OkHttp文档应该打印:

https://www.google.com/dummy/partialDummy

  • 谢谢你的回复.你能解释一下,在使用RxJava时我们怎么能做同样的事情?因为在这种情况下,返回类型将是Observable,那么如何获取request()和url? (3认同)
  • 如果我们在RxJava 2中使用Retrofit 2怎么办? (3认同)

小智 5

Log.d(TAG, "onResponse: ConfigurationListener::"+call.request().url());
Run Code Online (Sandbox Code Playgroud)