Note to self: Play-WS Scala send POST Request Multipart/Form-Data
17
May
2017
import play.api.mvc.MultipartFormData._
val url = "http://someAddress.com/withPostEndpoint"
val params: immutable.Iterable[DataPart] = Map(
"from" -> "sender@host.com",
"to" -> "user@host.com",
"subject" -> "mySubject",
"text" ->
s"""
|Hallo!
|blablabla
| """.stripMargin
).map { case (k, v) => DataPart(k, v) }
val parameterSource = Source.fromIterator(() => params.toIterator)
val f = wsClient
.url(url)
.post(parameterSource)
Code language: Scala (scala)