【发布时间】:2020-04-24 10:13:55
【问题描述】:
假设我们有以下请求:
curl --location --request POST 'localhost:8080/api' \
--header 'Content-Type: multipart/form-data' \
--form 'field1=value1' \
--form 'field2=value2'
下面的请求处理程序获取整个实体,但我正在努力寻找如何获取value1 和value2。
val requestHandler: Flow[HttpRequest, HttpResponse, _] = Flow[HttpRequest].mapAsync(1) {
case HttpRequest(HttpMethods.POST, Uri.Path("/api"), _, entity, _) =>
val entityTextFuture: Future[String] = entity.toStrict(3 seconds).map(_.data.utf8String)
entityTextFuture.flatMap { text =>
Future(HttpResponse(
StatusCodes.OK,
entity = text
))
}
}
重要提示:我必须使用 Akka HTTP 低级服务器 API,所以不能使用路由。
非常感谢您的宝贵时间和提前帮助!
【问题讨论】:
标签: scala httprequest multipartform-data httpresponse akka-http