java - 从 Spring Boot 应用程序中的请求和返回值派生内容类型
问题描述
在 Spring boot 应用程序中,通过 Aspect,我想要 HttpRequest 和 HttpResponse 的内容类型。基本上,我想确定关联的内容类型是否为application/json
.
到目前为止,我已经编写了以下代码片段:
public void captureRequest(JoinPoint joinPoint, Object returnValue) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes())
.getRequest();
String requestContentType = ???? <--CANNOT UNDERSTAND WHAT TO WRITE HERE
if(requestContentType.equals("application/json") {
...
}
String responseContentType = ??? <-- CANNOT UNDERSTAND HOW TO DERIVE CONTENT TYPE FROM RETURN VALUE
}
编辑:
在这方面,在浏览了这里关于 SO 的几篇文章之后,我想,会有一个关键:Content-Type
作为标题中的关键之一。但是当我按如下方式打印标题名称时,我没有找到任何 key Content-Type
。我只找到以下键:
Cookie
Accept
Connection
User-Agent
Sec-Fetch-Site
Sec-Fetch-Dest
Host
Accept-Encoding
Sec-Fetch-Mode
Accept-Language
如前所述,在上面的代码片段中,我想派生请求和返回值的内容类型。有人可以帮忙吗?
解决方案
推荐阅读
- python - MoveTargetOutOfBoundsException - Python 网页抓取
- c++ - C++ 使用 32 位和 64 位库编译应用程序
- javascript - 使 React 表按字母顺序排序
- c++ - 如何从我的主窗口停止在我的对话框类中运行的线程
- java - 未能执行目标 com.spotify:docker-maven-plugin:1.2.1:build (build-image)
- javascript - 使用保留字 const 定义的变量
- c# - c# 具有 2 个键的隐式泛型类型
- mongodb - 当我创建一个 $group 时,如何返回所有对象中存在的属性的总和?
- python - 关闭 MacBook 盖子后 Python 线程池挂起
- webpack - 使用 Webpack 的“dependOn”,每个条目有多个文件