How to Extract Values from Response Header in JMeter?

JMeter is a powerful tool for API testing. Let’s say you are are writing test cases for one of your RESTful service; and you want to extract and validate the value returned as part of response header.

It is little bit tricky to extract the value from Response Header in JMeter, but it is possible. For example, your RESTful service returns “ETag” in response header. When you look at the raw response data, the value is displayed something like this:

  • ETag: 2666d92fa9ebf10250acdb235546f045

To exact value of this reaponse header in JMeter:

  • Right click on your HTTP request, then add Post Processor element – Regular Expression Extractor
  • Select Radio button – Main sample only
  • Select Radio burron – Response Headers
  • Type some name in Reference Name section – for example, eTagVariable
  • Type this expression in Reference Expression section – ETag:\s+(.+)
    • IMPORTANT: This expression will select pick the ETag response header parameter and select everything after colon blank space i.e. actual value of ETag response header parameter.
  • Type this in Template section – $1$ 
  • Now, the ETag value is stored as JMeter variable and you can use it for validation or to pass in next HTTP request.
  • To get the value, use ${eTagVariable}

Leave a Reply

Your email address will not be published. Required fields are marked *