我在Play中创建一个Scala函数!验证请求到我的网络服务的应用程序。认证基本上是HMAC认证。该方法接收要使用的bodyParser的类型。由于我不知道-bodyParser的类型,我如何将request.body转换为可以运行我的MD5处理的通用Array [Byte]?如何将request.body转换为字节数组以计算MD5?
def Authenticated[T](authType : AuthenticationType, bodyParser : BodyParser[T])(f : (Request[T]) => Result) = {
Action(bodyParser) { request =>
// Authentication logic starts here
// TODO: Something like: var bodyData : Array[Byte] = request.body.toByteArray()
// The rest is easy...
var contentMD5 = calculateMD5(bodyDat)
f(request)
}
}
见http://stackoverflow.com/questions/4905393/scala-inputstream-to-arraybyte – 2012-07-24 04:33:23