2016-09-12 75 views
0

我想使用下面的代码使用akka http客户端调用Rest API。Akka http客户端 - URI编码

  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返回错误。有没有选择我们可以让阿卡不篡改URI?

回答

0

我还没有试过,但Sprayakka-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和测试。

+0

我试过,但没有帮助。 uri = Uri.apply(“https://example.com/customers/~/profiles/dj2bQryHPCj4IVrc48xTPD%2Bhswk%2FqNWx%2BLuUA0G2T6GLnyBVD6wC231IjgDBYJnt/preferences”,Uri.ParsingMode.Relaxed), – Leo15