Trouble in passing “=” (equal) symbol in subsequent request - Jmeter

冷暖自知 提交于 2019-12-14 03:18:52

问题


I newly started using jmeter. my application returns an url with encryption value as response which has to be passed as request to get the next page. The encryption value always ends with "=" ex. "http://mycompany.com/enc=EncRypTedValue=". while passing the value as request, the "=" is replaced with some other character like '%3d' ex "http://mycompany.com/enc=EncRypTedValue%3d" . Since the token has been changed my application is not serving the request.


回答1:


It took me a while to understand this, unlike other languages and environments in network standards URIs (URLs) do not use quotes or some escape characters to hide special characters.

Instead, a URL needs to be properly encoded by encoding each individual parameter separately in order to build the complete URL. In JavaScript encoding/decoding of the parameters is done with encodeURIComponent() and decodeURIComponent() respectively.

For example, the following:

http://example.com/?p1=hello=hi&p2=three=3

should be encoded using encodeURIComponent() on each parameters to build the following:

http://example.com/?p1=hello%3Dhi&p2=three%3D3

  • Note that the equal sign used for parameters p1= ... p2= remain as is.
  • Do not try encode/decode the whole URL, it won't work. :)
  • Do not be fooled by what is displayed on a browser address bar/field, that is only the human friendly string, the moment you copy it to the clipboard the browser will encoded it.

Hope this helps someone.




回答2:


Your application has a problem then, because that's the way it should be sent. Url parameters should be encoded as specified in rfc3986. Browsers can do it automatically even, so that's something that should be fixed on your web app, if it is not working.

If data for a URI component would conflict with a reserved character's purpose as a delimiter, then the conflicting data must be percent-encoded before the URI is formed.

  reserved    = gen-delims / sub-delims

  gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"

  sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
              / "*" / "+" / "," / ";" / "="



回答3:


What you are experiencing is URL Encoding - = is a reserved character in URLs and you cannot just append it to your URL unencoded. It needs to be encoded. This obviously already happened in your case. On the server side the url parameters need to be decoded again. This is the job of the container normally, though.




回答4:


Basing on your use case you may with to consider one of the following approaches:

  1. You can use Regular Expression Extractor Post Processor to capture you response and store it to JMeter variable. As variables as Java Unicode Strings you shouldn't experience any problem with extra encoding of your "=" symbol.

  2. JMeter provides __urldecode function which you can utilize to decode your request.

  3. You can pre-process the request with kind of __Beanshell function or BeanShell preprocessor to decode the whole URL with something like:

    URLDecoder.decode(vars.get("your_URL_to be decoded"),"encoding");
    



回答5:


If your are adding encryption values in the subsequent request as request parameter then make sure 'Encoding?' is unchecked




回答6:


Use quotes for your values. E.g. -Jkey="val=ue"



来源:https://stackoverflow.com/questions/19994959/trouble-in-passing-equal-symbol-in-subsequent-request-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!