![](/img/trans.png)
[英]Can HTTP response body be empty when response header 'Content-Type' is set to 'application/json'?
[英]Akka http Explicitly set HTTP header 'Content-Type: application/json' is ignored
我有這樣的代碼:
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))
但同樣的結果..
如前所述,您向實體添加了正確的內容類型,但您需要刪除ctJson
標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.