我正在尝试使用以下代码使用akka http客户端调用Rest API。
val httpRequest = HttpRequest(
method = HttpMethods.GET,
uri ="https://example.com/customers/~/profiles/dj2bQryHPCj4IVrc48xTPD%2Bhswk%2FqNWx%2BLuUA0G2T6GLnyBVD6wC231IjgDBYJnt/preferences",
headers = List(Accept(MediaRange(MediaTypes.`application/json`.withParams(Map("v" → "3")))),
RawHeader("Content-Type", "application/json;v=3"),
RawHeader("Api-Key", "XYZ")
)
)
Http()。singleRequest(httpRequest,GatewayHelper.connectionContext)
在通话结束之前,当我检查httprequest.uri(通过调试器)时,会发生部分uri解码(%2B更改为+) dj2bQryHPCj4IVrc48xTPD + hswk%2FqNWx + LuUA0G2T6GLnyBVD6wC231IjgDBYJnt
因此,API返回错误。我们可以选择让akka不要篡改URI吗?
答案 0 :(得分:0)
我没有尝试过这个,但Spray
和akka-http
有一些配置选项来修改URI的严格性。
看看这个:http://doc.akka.io/docs/akka/2.4.10/scala/http/configuration.html#akka-http
以下参数
设置解析请求目标URI的严格模式。
# The following values are defined: # # `strict`: RFC3986-compliant URIs are required, # a 400 response is triggered on violations # # `relaxed`: all visible 7-Bit ASCII chars are allowed # uri-parsing-mode = strict
您可能希望将其更改为relaxed
并再次测试。