2016-09-12 73 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