skip to Main Content

I am trying to load test the checkout process for the Magento 2 API using JMeter. We are expecting 1000 concurrent users.

The following curl command works fine:

curl -g -X GET "https:/oursite.com/rest/V1/products/25006A/" -H "Authorization: Bearer tm2yd2908exmy0ntoq9esvr5gqoh7upp"

However when I put in the same Authorization Bearer in the header for JMeter to the same URL it does not return the JSON. Instead it throws a 400 Bad Request. What other headers do I need?

Here is what I have for JMeter script:

<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Get Products" enabled="true">
  <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
    <collectionProp name="Arguments.arguments"/>
  </elementProp>
  <stringProp name="HTTPSampler.domain">${varDomain}</stringProp>
  <stringProp name="HTTPSampler.port"></stringProp>
  <stringProp name="HTTPSampler.protocol">https</stringProp>
  <stringProp name="HTTPSampler.contentEncoding"></stringProp>
  <stringProp name="HTTPSampler.path">/rest/V1/products/25006A/</stringProp>
  <stringProp name="HTTPSampler.method">GET</stringProp>
  <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
  <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
  <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
  <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
  <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
  <stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
  <stringProp name="HTTPSampler.connect_timeout"></stringProp>
  <stringProp name="HTTPSampler.response_timeout"></stringProp>
</HTTPSamplerProxy>
<hashTree>
  <HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
    <collectionProp name="HeaderManager.headers">
      <elementProp name="" elementType="Header">
        <stringProp name="Header.name">Authorization Bearer</stringProp>
        <stringProp name="Header.value">${varToken}</stringProp>
      </elementProp>
      <elementProp name="" elementType="Header">
        <stringProp name="Header.name">content-type</stringProp>
        <stringProp name="Header.value">application/json</stringProp>
      </elementProp>
    </collectionProp>
  </HeaderManager>
  <hashTree/>
</hashTree>

3

Answers


  1. Try and add view results tree listener and see what response message says. Usually that tells you what is wrong with the request.

    If I had to guess it is content-type or Accept header which you need to set to application/json.

    Hope this helps

    Login or Signup to reply.
  2. Your header name should be Authorization only

    Put Bearer ${varToken} as the value in header

    Login or Signup to reply.
  3. Since JMeter 5.1 there is a possibility to create a JMeter Test Plan from curl command

    1. From JMeter’s main menu choose Tools -> Import from cURL
    2. Use the following command:

      curl "https:/oursite.com/rest/V1/products/25006A/" -H "Authorization: Bearer tm2yd2908exmy0ntoq9esvr5gqoh7upp"
      
    3. That’s it, JMeter will generate HTTP Request sampler and HTTP Header Manager with correct values

      enter image description here


    The problem with your script is that the header name should be Authorization and header value should be Bearer tm2yd2908exmy0ntoq9esvr5gqoh7upp

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search