2016-04-14 65 views
1

FormData應該自動設置Content-Type標題,但它不起作用。所以我試圖手動設置它,但我得到一個警告。Spray沒有爲FormData設置Content-Type標題

val gzipPipeline: HttpRequest => Future[HttpResponse] = encode(Gzip) ~> sendReceive ~> decode(Gzip) 

val request = 
     (Post(uri, 
     FormData(Map(
      "set_login" -> credentials.username, 
      "set_pass" -> credentials.password)) 
    ) ~> addHeader(`Content-Type`(`application/x-www-form-urlencoded`)) 
     ~> addHeader(`Accept-Encoding`(gzip))) 

[WARN] [04/14/2016 02:09:50.803] [forPipeline-akka..default-dispatcher-8] [akka://forPipeline/user/IO-HTTP/group-0/0] Explicitly set request header 'Content-Type: application/x-www-form-urlencoded' is ignored, the request Content-Type is set via the request's HttpEntity! 

在任何情況下,我從服務器得到的迴應是,當我沒有設置Content-Type頭,我得到了響應。

我是否正確構建了管道和HttpEntity?我是否應該使用編組器FormData

回答

0

我正確設置HttpRequest,但服務器不接受gzip編碼的請求。我只需要從管道中刪除gzip編碼。