Note to self: Play-WS Scala send POST Request Multipart/Form-Data

17 May
2017


import play.api.mvc.MultipartFormData._

val params: immutable.Iterable[DataPart] = Map(
"from" -> "xxx ",
"to" -> x.email,
"subject" -> "mySubject",
"text" ->
s"""Hallo!
| blablabla
""".stripMargin
).map { case (k, v) => DataPart(k, v) }

val par1 = Source.fromIterator(() => params.toIterator)

val f = wSClient
.url(configuration.getString("mailprovider.api.url").get + "/messages")
.withAuth("api", configuration.getString("mailprovider.api.key").get, WSAuthScheme.BASIC)
.post(par1)

Comment Form

top