我有这个:
class RichResponse(future: Future[WSResponse]) {
def failIfNot(statuses: Int*)(implicit executor: ExecutionContext) = {
future.map { response =>
if(statuses.contains(response.status)) {
response
} else {
throw new RuntimeException("Bad HTTP response for %s: %s".format(
response.ahcResponse.getUri, response.status))
}
}
}
}
object Implicits {
implicit def responseToRichResponse(future: Future[WSResponse]) = new RichResponse(future)
}
用法是这样的:
WS.url("http://stackoverflow.com/questions/ask").failIfNot(OK)
但是从 2.1 升级到 2.3 后,achResponse
不再存在。我如何才能获得底层(和更完整的)响应对象?
最佳答案
我开始阅读源代码,似乎
response.underlying[NingWSResponse].ahcResponse
将是执行此操作的新方法。
看起来不是很安全....
关于scala - 从 Play WS 获取 ahcResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25177143/