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
Source: stackoverflow.com
Related Query
- Idiomatic way to create a basic HTTP Post request with Akka HTTP
- Post request with Akka http
- Akka http add header to POST request with body
- How to http post with an empty body request using WS API in Playframework 2 / Scala?
- How do I create a POST request with form field content with Spray?
- How to send HTTP request using Akka with SSL certificates
- Akka http request is not consumed with runFold when it's piped to actor
- The idiomatic way to manage shared state with Akka Streams
- Akka HTTP how to POST singleRequest with Content-Type application/x-www-form-urlencoded
- How to read JSON body from Akka HTTP POST request and send the final response as JSON array
- Correct way to deal with a case of POST method request Http4s
- Tapir with Akka HTTP file upload - Sending an 2xx 'early' response before end of request was received
- How to implement Akka HTTP Request Post Client Headers Authorization
- Akka HTTP route post entity string, complete with Future
- Passing data with request using Akka http
- How can i handle multipart post request with akka http?
- How to handle this type of JSON request in akka http POST endpoint?
- Retrying Akka HTTP requests gets exponentially slower with each request
- Unable to Test POST request In Scala HTTP Akka
- Basic akka http client post not working
- Optimal way to create a ml pipeline in Apache Spark for dataset with high number of columns
- Idiomatic way to write multi-project builds with .sbt files in sbt 0.13
- Get http headers with akka routing dsl
- How to unmarshall akka http request entity as string?
- How to download a HTTP resource to a file with Akka Streams and HTTP?
- Akka Http Route Test: Request was neither completed nor rejected within 1 second
- What is the best way to work with akka from nodejs
- Idiomatic Scala way to deal with base vs derived class field names?
- Why does Akka fail with "IllegalStateException: cannot create children while terminating or terminated" when testing with ScalaTest?
- Is there a way to create dot-free dsl in scala with two identifiers between variables?
More Query from same tag
- Flink capture messages based on time window and process
- How to create pivot in read csv file with scala
- Why is the method accepts only one argument?
- Understanding Pattern Matching with Sub-classes
- Is there an analog in Scala for the Rails "returning" method?
- What is the use of FastFuture in akka
- Avoiding a cast when using Option.fold in scala
- Traits and method parameters in Scala
- How to do an infinite loop without blocking CPU
- collectFirst: Applying partial function with multiple case clauses
- Why does scalaz.NonEmptyList not support common list operations like "find"
- How to fix compiler warning on scala.xml.Elem
- What's the neatest way to define circular lists with Scala?
- Joda Time library in scala returning incorrect date
- What is the passthrough used for in alpakka-kafka connector while producing messages?
- How to select 13 digit timestamp column from parquet file,convert it to date and store as a data frame?
- Play Framework 2.2.1 / How should controller handle a queryString in JSON format
- Scala: Lambda cannot be cast to ClassTag error
- simple scala question about httpparser
- Scala custom operator (example abs)
- Scala missing parameter type for expanded function
- How do I create a class hierarchy of typed factory method constructors and access them from Scala using abstract types?
- NoClassDefFoundError for Play app with sbt using Eclipse
- Check if values in a column contains values other than alphabets or spaces
- sender inside a future
- Functions vs function pointers
- Cloud Storage Client with Scala and Dataproc: missing libraries
- scala - why map.size return 0 when the map is not empty
- What is the best way to find and replace element in immutable set in Scala?
- Regex RDD using Apache Spark Scala