Spray没有为FormData设置Content-Type标头

时间:2016-04-14 09:15:50

标签: scala spray spray-client

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的编组人员吗?

1 个答案:

答案 0 :(得分:0)

我正确设置了HttpRequest,但服务器不接受gzip编码的请求。我只需要从管道中删除gzip编码。

相关问题