Jmeter Http代理服务器抛出java.net.URISyntaxException:索引错误时查询中的非法字符

时间:2017-01-26 13:43:06

标签: java jmeter urlencode put

我正在尝试使用Jmeter记录我的Web客户端 - 服务器通信。配置Jmeter和浏览器以记录应用程序之后。从客户端到服务器发出post请求时,会发生以下错误。知道如何编码正在记录的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)

1 个答案:

答案 0 :(得分:2)

具体而言,该异常是关于URI中的花括号:

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

将括号括起来unsafe

  

其他字符不安全,因为已知网关和其他传输代理有时会修改此类字符。这些字符是&#34; {&#34;,&#34;}&#34;,&#34; |&#34;,&#34; \&#34;,&#34; ^&# 34;,&#34;〜&#34;,&#34; [&#34;,&#34;]&#34;和&#34;`&#34;。所有不安全的字符必须始终在URL中编码。

因此,您可以将{的所有实例替换为%7B,将}的所有实例替换为%7D。我的猜测是录音机不对它们进行编码,因为大括号不是&#34;特殊的&#34;字符(它们只是&#34;不安全&#34;),而URI解析器不喜欢它们。因此,您可以将其视为JMeter刻录机中的错误。因此,最小的解决方案是将路径设置为:

/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

但是,我认为更优雅的解决方案是在参数部分中保存所有参数(超过?标记),这样做几乎没有优势:

  1. 它有一个自动编码的选项
  2. 您可以清楚地看到要发送的参数
  3. 您可以在需要时使用变量而不是静态值(您也可以在Path中使用变量,但不能没有很多繁琐且容易出错的配置)
  4. 以下是我将如何创建此请求的屏幕截图:

    enter image description here

    由于方法设置为GET,所有参数都会成为网址的一部分,但是它们会被正确编码,所以这里的方法是&#39 ;发送:

    enter image description here