Scala 在Spray客户端上添加基本身份验证
我正试图通过以下方式从Scala 在Spray客户端上添加基本身份验证,scala,akka,spray,Scala,Akka,Spray,我正试图通过以下方式从scala/spraycode建立与Url的连接: val Response = HttpDialog(Http.Connect("Url", port = 80, sslEncryption = true)).send(Get(String.format(endpoint, parameter1, parameter2))).end Url需要进行身份验证,我需要在上面的Http请求中为其添加一个包含base64编码用户名:密码字符串的授权头 如何添加授权标头 谢谢,
scala/spray
code建立与Url的连接:
val Response = HttpDialog(Http.Connect("Url", port = 80, sslEncryption = true)).send(Get(String.format(endpoint, parameter1, parameter2))).end
Url需要进行身份验证,我需要在上面的Http请求中为其添加一个包含base64编码用户名:密码字符串的授权头
如何添加授权标头
谢谢,
arbit.您可以使用RequestTransformer转换Get,特别是spray.httpx.RequestBuilding.addCredentials
val Response = HttpDialog(...).send(
Get(String.format(endpoint, parameter1, parameter2)) ~> addCredentials(BasicHttpCredentials(username, password))
).end
如果您仔细查看源代码,它所做的只是为这些凭证添加一个HttpAuthorization标头,即addHeader转换器。您可以使用RequestTransformer转换Get,特别是spray.httpx.RequestBuilding.addCredentials
val Response = HttpDialog(...).send(
Get(String.format(endpoint, parameter1, parameter2)) ~> addCredentials(BasicHttpCredentials(username, password))
).end
如果您仔细查看源代码,它所做的就是为那些凭证添加一个HttpAuthorization头,即addHeader转换器