我正在使用喷雾客户端通过Get调用连接到API。下面是代码:
val response = HttpDialog(URI)
.send(Get(String.format("message=%s",message)))
.end
我上面的消息是"嗨%20!@#$%,:()。~"
但是在连接时,我得到IllegalUriException。甚至尝试在配置文件中使用uri-parsing-mode = relax -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]
因为您在查询和片段位置使用了禁用符号。转换为urlencoded字符串(Hi%2520!%40%23%24%25%2C%3A().%3F%7E%60
)有帮助