gpt4 book ai didi

java - 喷雾 - IllegalURI 异常

转载 作者:行者123 更新时间:2023-12-02 04:30:31 26 4
gpt4 key购买 nike

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

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

我上面的消息是“Hi%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 ) 会有所帮助。

关于java - 喷雾 - IllegalURI 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31535932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com