记录请求和响应主体

记录请求和响应主体

本文介绍了如何使用 Retrofit-Android 记录请求和响应主体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Retrofit API 中找不到用于记录完整请求/响应主体的相关方法.一世期待 Profiler 中的一些帮助(但它只提供有关响应的元数据).我尝试在 Builder 中设置日志级别,但这也无济于事:

I can't find relevant methods in the Retrofit API for logging complete request/response bodies. Iwas expecting some help in the Profiler (but it only offers meta-data about response). I tried setting the log level in the Builder, but this doesn't help me either :

RestAdapter adapter = (new RestAdapter.Builder()).
                setEndpoint(baseUrl).
                setRequestInterceptor(interceptor).
                setProfiler(profiler).
                setClient(client).
                setExecutors(MyApplication.getWebServiceThreadPool()).
                setLogLevel(LogLevel.FULL).
                setLog(new RestAdapter.Log() {
                    @Override
                    public void log(String msg) {
                        Log.i(TAG, msg);
                    }
                }).
                build();

此代码现在正在运行.我不知道为什么它不能早点工作.可能是因为我使用了一些旧版本的改造.

This code is working now. I don't know why it wasn't working earlier. Possibly because I was using some older version of retrofit.

推荐答案

我使用了 setLogLevel(LogLevel.FULL).setLog(new AndroidLog("YOUR_LOG_TAG")),对我有帮助.
更新.
您也可以尝试出于调试目的使用retrofit.client.Response作为响应模型

I used setLogLevel(LogLevel.FULL).setLog(new AndroidLog("YOUR_LOG_TAG")), it helped me.
UPDATE.
You can also try for debug purpose use retrofit.client.Response as response model

这篇关于如何使用 Retrofit-Android 记录请求和响应主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 07:56