我正在尝试使用 AndroidAnnotation 的其余客户端访问 Web 服务。我收到以下错误:
org.springframework.http.converter.HttpMessageNotReadableException:
Could not read JSON: Unexpected character ('f' (code 102)):
was expecting double-quote to start field name
如何让其余客户端记录它收到的实际响应?我无法想象为什么我的 Web 服务会返回此响应,但除非我能看到完整的响应,否则我无法调试它。我是否必须在 Spring 框架级别设置某种选项?
我还想查看我发送的请求的正文。
感谢您的帮助!
最佳答案
Here我们看到 AndroidAnnotations 是 Spring Android RestTemplate 模块的包装器。 RestTemplate
的代码是 here .所以我们可以找出哪个TAG用于日志记录:
private static final String TAG = "RestTemplate";
您是否看不到此 TAG 的日志条目?您使用哪种转换器/提取器?请发布调用堆栈。
在wiki他们建议使用 Interceptor
来记录请求/响应。所以你可以像这样实现你自己的拦截器:
public class LoggingInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] data, ClientHttpRequestExecution execution) throws IOException {
logRequest(request);
ClientHttpResponse response = execution.execute(request, data);
logResponse(response);
return response;
}
private void logRequest(HttpRequest request) {
// log it
}
private void logResponse(ClientHttpResponse response) {
// log it
}
}
您在 @Rest
注释(字段 interceptors
)中启用拦截器。
关于android - AndroidAnnotations 的 Rest 客户端日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24493615/