Scala Akka Http无法读取响应正文?
我在scala/akka http项目中具有以下功能:Scala Akka Http无法读取响应正文?,scala,akka,Scala,Akka,我在scala/akka http项目中具有以下功能: def fetchResponse(userIdentifier: String, password: String): Future[HttpResponse] = { myResource(userIdentifier, password).map( result => if(result.status.intValue() == 201){ val bo
def fetchResponse(userIdentifier: String, password: String): Future[HttpResponse] = {
myResource(userIdentifier, password).map(
result =>
if(result.status.intValue() == 201){
val body = result.headers.collect {
case c: `Set-Cookie` => c.cookie
}.find(_.name == "SSO").getOrElse(HttpCookie("SSO", "")).value
HttpResponse(result.status.intValue(), entity = body)
}
else {
val body =
result.httpMessage.entity().toString
println(result)
HttpResponse(result.status.intValue(),entity = body)
}
)
}
此方法通过以下函数调用myMethod api:
def myResource(userIdentifier:String,password:String): Future[HttpResponse] = {
Http().singleRequest(HttpRequest(uri = Uri("http://localhost:9090/information"),
method = HttpMethods.POST,
entity = {
FormData(Map("userIdentifier" -> userIdentifier, "password" -> password)).toEntity(HttpCharsets.`UTF-8`)
}
)
.withHeaders(
RawHeader("Content-Type", "application/x-www-form-urlencoded"),
RawHeader("Accept", "application/vnd.siren+json")
))
}
但是,当我从第一个函数中调用第二个函数时,它只返回响应状态,而不是返回如下的主体:
HttpEntity.Chunked(application/octet-stream)
将显示以下警告:
(WaitingForResponseEntitySubscription)] Response entity was not subscribed after 1 second. Make sure to read the response entity body or call `discardBytes()` on it.
我不知道是什么问题 我也有同样的问题。你把这个修好了吗?