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

时间:2018-08-10 13:34:59

标签: json scala akka-http

我有类似的代码:

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))

但结果相同。

1 个答案:

答案 0 :(得分:0)

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