【问题标题】:Spring Webflux Webclient | Content type headers set issueSpring Webflux Webclient |内容类型标题设置问题
【发布时间】:2019-08-22 09:52:38
【问题描述】:

我设置标题的方式如下:

import org.springframework.web.reactive.function.client.WebClient;

WebClient webClient = WebClient.create();
webClient.post().uri(url)
        .headers(httpHeaders -> httpHeaders.setAll(headersMap))
        .body(BodyInserters.fromFormData(HelperMethods.mapToMultiValueMap(body))).exchange();

它适用于某些服务,但我在添加自定义标头基础要求时遇到问题。

为了设置内容类型,我在 headersMap 的标题中添加了以下内容(headersMap 是一个 Map):(“Content-Type”,“application/json”)

但它给了我错误:“HTTP 标头行 ["Content-Type": "application/json"] 不符合 RFC 7230 并已被忽略"

这可能是什么原因造成的?我尝试发送内容类型,例如:(“content-type”,“application/json”),但错误是一样的。

我无法使用“.contentType()”在请求中设置标头,因为标头的数量是可变的,在 headersMap 中动态设置。

【问题讨论】:

    标签: java spring-boot spring-webflux spring-webclient


    【解决方案1】:

    您正在发送内容类型指向 json 的表单数据(通常为 Content-Type: multipart/form-data) - 发送正确的 JSON 或将您的标头更改为适合表单数据。

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 2020-08-02
      • 2020-12-31
      • 2017-01-16
      • 2019-04-13
      • 2018-08-06
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      相关资源
      最近更新 更多