【问题标题】:How to see what's inside POST-query? Retrofit 2如何查看 POST 查询中的内容?改造 2
【发布时间】:2018-01-18 20:57:22
【问题描述】:

我向服务器查询,但出现错误。请告诉我,我如何查看我的查询以查看错误在哪里。如何在 Retrofit 2 中记录 API 调用?

【问题讨论】:

标签: android post request retrofit


【解决方案1】:

您可以通过使用 Interceptor 来记录所有请求来改造 HttpClient 例如,您可以在 gradle 文件中按照以下步骤在 OkHttp 中添加 HttpInterceptor 依赖项:

compile 'com.squareup.okhttp3:logging-interceptor:3.4.0'

然后

OKHttp client = ....
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
client.interceptors().add(interceptor);

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("url")
            .client(client) // add custom OkHttp client

【讨论】:

    猜你喜欢
    • 2016-03-07
    • 2016-08-12
    • 2011-10-25
    • 2012-01-17
    • 1970-01-01
    • 2013-04-08
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多