akka HttpResponse将主体读取为String scala

编程入门 行业动态 更新时间:2024-10-11 03:23:17
本文介绍了akka HttpResponse将主体读取为String scala的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我有一个带有此签名的函数(akka.http.model.HttpResponse):

So I have a function with this signature (akka.http.model.HttpResponse):

def apply(query: Seq[(String, String)], accept: String): HttpResponse

我只是得到一个值像这样的测试:

I simply get a value in a test like:

val resp = TagAPI(Seq.empty[(String, String)], api.acceptHeader)

我想在测试中检查其主体,例如:

I want to check its body in a test something like:

resp.entity.asString == "tags"

我的问题是如何以字符串形式获取响应正文?

My question is how I can get the response body as string?

推荐答案

import akka.http.scaladsl.unmarshalling.Unmarshal implicit val system = ActorSystem("System") implicit val materializer = ActorFlowMaterializer() val responseAsString: Future[String] = Unmarshal(entity).to[String]

更多推荐

akka HttpResponse将主体读取为String scala

本文发布于:2023-11-25 06:41:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主体   HttpResponse   akka   String   scala

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!