问题
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:
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.
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