【问题标题】:How to parse body of Content-type: application/vnd.contentful.management.v1+json如何解析 Content-type 的主体:application/vnd.contentful.management.v1+json
【发布时间】:2016-11-15 03:13:21
【问题描述】:

我正在尝试解析请求正文,其中

Content-type: application/vnd.contentful.management.v1+json

当我给Content-type: application/json

它工作正常,但 Contentful CMS 传递了上述内容类型,所以我必须以某种方式解析它。

【问题讨论】:

    标签: java playframework-2.5 contentful


    【解决方案1】:

    您似乎在使用内容丰富的 Java SDK 对吗?

    该标头由 SDK 填充,您是否需要解析该标头?

    【讨论】:

    • 我正在尝试将我的 webhook 集成到 Contentful 中。 contentful 触发带有标头 Content-type 的 api:application/vnd.contentful.management.v1+json 并且我的 java play 应用程序无法解析正文。因为它期望 application/json 作为 Content-type
    • @Indrajeet 你不能只期望代码中的标头而不是应用程序/标头
    【解决方案2】:

    我找到了解决方案。

    如果正文是 json 类型,则默认在 header 中查找 Content-type application/json。

    为了避免 Content-Type 标头的验证是 JSON,我使用了这个并且它有效。

    @BodyParser.Of(BodyParser.TolerantJson.class)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-23
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 2019-10-26
      • 2023-04-07
      • 2013-04-07
      相关资源
      最近更新 更多