Akka http明确设置HTTP标头'Content-Type:application / json'被忽略

问题描述 投票:0回答:1

我有类似的代码:

val request = HttpRequest(
      method = HttpMethods.POST,
      uri = Uri(url))
      .withHeaders(List(authorization, ctJson))
      .withEntity(ContentTypes.`application/json`, ByteString(jsonStr))
 Http().singleRequest(request)

效果很好,但在请求过程中出现警告:

明确设置HTTP标头'Content-Type:application / json'为忽略,不允许显式Content-Type标头。组改为HttpRequest.entity.contentType

如何解决此问题?我也尝试过:

val request = HttpRequest(
      HttpMethods.POST,
      uri = "https://api.sendgrid.com/v3/mail/send",
      entity = HttpEntity(ContentTypes.`application/json`, ByteString(jsonStr)),
      headers = List(authorization, ctJson))

但结果相同。。

我有这样的代码:val request = HttpRequest(method = HttpMethods.POST,uri = Uri(url)).withHeaders(List(authorization,ctJson)).withEntity(ContentTypes.`application / json`,...] >

json scala akka-http
1个回答
0
投票

如上所述,您向实体添加了适当的内容类型,但是您需要删除ctJson标头。

© www.soinside.com 2019 - 2024. All rights reserved.