Set the whole request url in jmeter

烂漫一生 提交于 2020-06-29 02:55:13

问题


I have a request, which gives upload url as response body.

{
    "uploadUrl": "https://test.com:9000/sample_uploadurl"
}

I'm able to extract the uploadUrl using JSON extractor.

I want to use above upload url to in next http request. How to set the new request here ?

adding directly doent work, because JMeter prepends http/https before request, in this case we already have https.

It got failed because it has https://[https://test.com:9000/sample_uploadurl]


回答1:


Leave HTTP Request fields empty except Path, put there the variable and it will be executed

As a special case, if the path starts with "http://" or "https://" then this is used as the full URL.

example




回答2:


The options are in:

  1. Put the whole ${UPLOAD_URL} to "Path" field of the HTTP Request sampler like:

    however this approach might be flaky and cause the malfunction of certain configuration elements like HTTP Cookie Manager. So it's better to go for option 2.

  2. Split the ${UPLOAD_URL} into individual components like protocol, host, port and path.

    • Add JSR223 PostProcessor after the JSON Extractor
    • Put the following Groovy code into "Script" area:

      URL url = new URL(vars.get('UPLOAD_URL'))
      
      vars.put('protocol', url.getProtocol())
      vars.put('host', url.getHost())
      vars.put('port', url.getPort() as String)
      vars.put('path', url.getPath())
      
    • The above code will generate the following JMeter Variables

    • So you should be able to use the generated variables in the next HTTP Request sampler:



来源:https://stackoverflow.com/questions/57562861/set-the-whole-request-url-in-jmeter

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