0

我有一个带有 REST 端点的基本 Spring Boot 应用程序,该端点配置为接收带有Content-Type=的 POST application/json

我的外部合作伙伴向我发布了 HTTP 请求,但显然使用了不同的Content-Type,因为我的应用程序拒绝了那些带有 HTTP 415 Unsupported Media Type 的请求。

不幸的是,Spring 的日志没有透露 Content-Type 到底是什么,并且外部合作伙伴目前无法回答问题。

有没有办法提高 Spring 的日志级别,以便日志还包括接收Content-Type到的被拒绝的内容?

4

1 回答 1

1

如上述评论中所述,我看到以下选项:

  1. 使用像wireshark这样的外部数据包分析器
  2. 使用 httptrace 执行器,您可以在此处查看示例
  3. 写一个拦截器,你可以在这里看到

使用 httpTrace 执行器

httptrace提供有关 HTTP 请求/响应交换的信息可以通过访问 /actuator/httptrace 来调用它。可以使用curl

$ curl 'http://localhost:8080/actuator/httptrace' -i -X GET

或直接从浏览器,在本地机器上http://localhost:8080/actuator/httptrace

信息以 JSON 格式提供:

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 503

{
  "traces" : [ {
    "timestamp" : "2019-12-06T06:13:02.341Z",
    "principal" : {
      "name" : "alice"
    },
    "session" : {
      "id" : "41a5c57b-112a-4b15-8ea9-05c5942e7e88"
    },
    "request" : {
      "method" : "GET",
      "uri" : "https://api.example.com",
      "headers" : {
        "Accept" : [ "application/json" ]
      }
    },
    "response" : {
      "status" : 200,
      "headers" : {
        "Content-Type" : [ "application/json" ]
      }
    },
    "timeTaken" : 1
  } ]
}
于 2020-01-10T09:33:00.800 回答