喷涂 - IllegalURI例外

时间:2015-07-21 10:00:52

标签: java scala http 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

以下是stacktrace:

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]

1 个答案:

答案 0 :(得分:2)

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