【问题标题】:Spring WebClient unsupported Content-TypeSpring WebClient 不支持的 Content-Type
【发布时间】:2019-04-15 19:02:23
【问题描述】:

我开始使用 Spring WebClient 向外部服务发送请求。 其中一项不受我控制的服务以 Json 响应,但响应标头中有 Content-Type“文本”。

status: 200
server: nginx/1.12.2
date: Tue, 13 Nov 2018 01:48:23 GMT
content-type: text

当我调用bodyToMono(String.class)toEntity(String.class) 时,这会使WebClient 失败并出现以下异常:

Caused by: org.springframework.util.InvalidMimeTypeException: Invalid mime type "text": does not contain '/'

我试图在这里查看我的选项,但我没有看到。 我无法即时更改标题(我看到了这篇文章:Reactive WebClient GET Request with text/html response 但它不起作用) 我无法让 WebClient 接受没有 / 的 mime 类型。

有人可以帮忙吗?

【问题讨论】:

    标签: spring spring-webflux


    【解决方案1】:

    作为消费者,我可以使用 Spring WebClient 在我的 Java 客户端接收字符串响应,内容类型为:生产者提供的文本/javascript。

    如果您是作为文本发送内容类型的服务的生产者,建议让它以正确的格式发送内容类型。

    例如:应用程序/json, 申请/pdf, 文本/javascript

    【讨论】:

      猜你喜欢
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      • 2012-04-26
      • 2018-02-28
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多