score:6

Accepted answer

Apparently a toEntity method was added to the FormData class at some point. So this now seems like the simplest solution to the problem:

val formData = FormData(combinedParams).toEntity
val r = HttpRequest(POST, url, headers, formData)

score:0

You can also use RequestBuilding:

Http().singleRequest(RequestBuilding.Post(url, formData)).flatMap(Unmarshal(_).to[String])

score:18

You can use Marshal in a for comprehension with other Futures, such as the ones you need to send the request and unmarshall the response:

val content = for {
        request <- Marshal(formData).to[RequestEntity]
        response <- Http().singleRequest(HttpRequest(method = HttpMethods.POST, uri = s"http://example.com/test", entity = request))
        entity <- Unmarshal(response.entity).to[String]
      } yield entity

Related Query

More Query from same tag