Spray - IllegalURI 异常

Spray - IllegalURI exception

我正在使用 Spray 客户端通过 Get 呼叫连接到 API。 以下是相关代码:

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

我上面的留言是“嗨%20!@#$%,:().?~`”

但是在连接时,我收到 IllegalUriException。甚至尝试在 conf 文件中使用 uri-parsing-mode = relaxed-with-raw-query

以下是堆栈跟踪:

spray.http.IllegalUriException: Illegal URI reference, unexpected character    
',' at position 128: 
URI?message=Hi%20!@#$%,:().?~`                                                                                                                               
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]

因为你在query and fragment positions中使用了禁止使用的符号。转换为 urlencoded 字符串 ( Hi%2520!%40%23%24%25%2C%3A().%3F%7E%60 ) 有帮助。