2015-07-21 54 views
0

我通過使用噴霧客戶端獲取呼叫連接到API。 以下是代碼爲:噴霧 - IllegalURI異常

val response = HttpDialog(URI) 
    .send(Get(String.format("message=%s",message))) 
    .end 

上面我的消息是 「Hi%20 @#$%:()〜`!?」

但同時連接,我得到IllegalUriException。甚至嘗試在conf文件中使用uri-parsing-mode =放寬原始查詢

以下是堆棧跟蹤:

spray.http.IllegalUriException: Illegal URI reference, unexpected character  
',' at position 128: 
URI?message=Hi%[email protected]#$%,:().?~`                                
at spray.http.Uri$.fail(Uri.scala:775) ~[spray-http_2.11-1.3.2.jar:na] 
at spray.http.parser.UriParser.complete(UriParser.scala:429) ~[spray- 
http_2.11-1.3.2.jar:na] 
at spray.http.parser.UriParser.parseReference(UriParser.scala:60) ~[spray- 
http_2.11-1.3.2.jar:na] 
at spray.http.Uri$.apply(Uri.scala:231) ~[spray-http_2.11-1.3.2.jar:na] 
at spray.http.Uri$.apply(Uri.scala:203) ~[spray-http_2.11-1.3.2.jar:na] 
at 
spray.httpx.RequestBuilding$RequestBuilder.apply(RequestBuilding.scala:36) ~ 
[spray-httpx_2.11-1.3.2.jar:na] 
at 
spray.httpx.RequestBuilding$RequestBuilder.apply(RequestBuilding.scala:34) ~ 
[spray-httpx_2.11-1.3.2.jar:na] 

回答

2

因爲你在query and fragment positions使用禁止符號。轉換爲urlencoded字符串(Hi%2520!%40%23%24%25%2C%3A().%3F%7E%60)有所幫助。

+0

請注意,您可以使用'Uri'構造函數爲您執行轉義操作,而不是「手工操作」。 – lmm