log4j - Unirest 如何在 Java 中记录请求和响应
问题描述
我刚开始使用 Unirest REST 框架,它很棒,但看不到任何选项来拦截和记录完整的请求和带有标题和正文的响应。有人知道如何实现吗?
解决方案
Unirest.config()
.intercepter(new LoggingInterceptor());
LoggingInterceptor.java
public class LoggingInterceptor implements kong.unirest.Interceptor {
@Override
public void onRequest(HttpRequest<?> request, Config config) {
// Log request
}
@Override
public void onResponse(HttpResponse<?> response, HttpRequestSummary request, Config config) {
// Log response
}
}
推荐阅读
- vba - 在 DoCmd.TransferDatabase 中使用连接字符串变量
- r - 如何在 R 中通过加权平均栅格化点数据?
- rest - Informatica BDM - 如何重试“REST Web 服务使用者”?
- javascript - 如何将逻辑语句引入 XML 视图或如何更改某些 Table 项目的展示方式
- r - Anova not working at multilevel analysis - "$ operator not defined for this S4 class"
- prometheus - Prometheus 同时监听不同的端口
- angular - 自动调整 textarea 最大 5 行限制,然后显示滚动条
- java - 如何仅使用 java 使用特殊字符(包括空格)创建大小为 5 的非重复随机字符串?
- kubernetes - Helm V3 - 找不到官方仓库
- python - 生成具有 60% 0 和 40% 1 的虚拟数据