gpt4 book ai didi

java - Jmeter Http 代理服务器抛出 java.net.URISyntaxException : Illegal character in query at index error

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:33:39 26 4
gpt4 key购买 nike

我正在尝试使用 Jmeter 记录我的 Web 客户端-服务器通信。在配置 Jmeter 和浏览器以记录应用程序之后。当从客户端向服务器发出发布请求时,会发生以下错误。知道如何对正在记录的 URL 进行编码吗?

java.net.URISyntaxException: Illegal character in query at index 238: http://localhost:8080/updateBoxCorrectionInstantly?examKey=16-17-%3ECBSE-%3ETERM%20I-%3ESA1-%3EVI-%3EScience-%3EA&studentName=AMOGH%20YOGESH%20KALE&studentRollno=3&studentND=-1&sheetName=cb8e806b32e9d670698655e0d2da10e3_img001210.jpg&box={%22$center%22:%22(66.0,%202253.0)%22,%22$conf%22:%22H%22,%22$corrected%22:true,%22$isAdminCorrected%22:true,%22$correction%22:%22-%22,%22$isDrawn%22:false,%22coords%22:[36,2214,96,2292],%22isTitle%22:false,%22pos%22:%22-%22,%22pred%22:%22-%22,%22boxTypeId%22:0,%22score%22:1}
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at java.net.URL.toURI(URL.java:949)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:232)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1075)
at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:212)

最佳答案

具体而言,该异常与 URI 中的大括号有关:

/updateBoxCorrectionInstantly?<...>_img001210.jpg&box={

大括号被视为unsafe :

Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.

因此您可以将 { 的所有实例替换为 %7B,并将 } 的所有实例替换为 %7D。我的猜测是记录器没有对它们进行编码,因为大括号不是“特殊”字符(它们只是“不安全”),而 URI 解析器不喜欢它们。所以你可以认为它是 JMeter 记录器中的一个错误。因此,最小的解决方案是将 Path 设置为:

/updateBoxCorrectionInstantly?examKey=16-17-%3ECBSE-%3ETERM%20I-%3ESA1-%3EVI-%3EScience-%3EA&studentName=AMOGH%20YOGESH%20KALE&studentRollno=3&studentND=-1&sheetName=cb8e806b32e9d670698655e0d2da10e3_img001210.jpg&box=%7B%22$center%22:%22(66.0,%202253.0)%22,%22$conf%22:%22H%22,%22$corrected%22:true,%22$isAdminCorrected%22:true,%22$correction%22:%22-%22,%22$isDrawn%22:false,%22coords%22:[36,2214,96,2292],%22isTitle%22:false,%22pos%22:%22-%22,%22pred%22:%22-%22,%22boxTypeId%22:0,%22score%22:1%7D

但是,我认为一个更优雅的解决方案是将所有参数(超过 ? 标记)保存在 Parameters 部分,这有一些优点:

  1. 它有自动编码的选项
  2. 您可以清楚地看到您发送的是哪些参数
  3. 您可以在需要时使用变量而不是静态值(您也可以在 Path 中使用,但并非没有大量繁琐且容易出错的配置)

这是我将如何创建此请求的屏幕截图:

enter image description here

因为 Method 设置为 GET,所有参数无论如何都将成为 URL 的一部分,但它们将被正确编码,因此发送方式如下:

enter image description here

关于java - Jmeter Http 代理服务器抛出 java.net.URISyntaxException : Illegal character in query at index error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41874849/

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