ajayramesh
ajayramesh

Reputation: 3774

Set the whole request url in jmeter

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. JSON extractor

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

enter image description 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]

Upvotes: 2

Views: 3733

Answers (2)

Dmitri T
Dmitri T

Reputation: 168002

The options are in:

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

    enter image description here

    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

      enter image description here

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

      enter image description here

Upvotes: 2

Ori Marko
Ori Marko

Reputation: 58774

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 example

Upvotes: 4

Related Questions