11
votes

I am getting following header in response : HTTP/1.1 200 OK Date: Mon, 11 Apr 2016 10:36:10 GMT content-disposition: attachment; filename=result.xml; x-xss-protection: 1; mode=access Keep-Alive: timeout=5, max=100 I want to read filename from header, how can I use regular expression to capture this value ?

2

2 Answers

22
votes
  1. Add Regular Expression Extractor as a child of the HTTP Request which returns above headers
  2. Configure it as follows:

    • Apply to: Main sample only or Main sample and sub-samples depending on whether header comes in main response or nested responses
    • Field to check: Response Headers. This bit is super important
    • Reference Name: anything meaningful, i.e. filename
    • Regular Expression: filename=(.+?);
    • Template: $1$

      Regular Expression Configuration

  3. Refer extracted value as ${filename} where required


  1. References:

0
votes

Use a PostProcessor element and refer required element with ctx.getPreviousResult().XXX, for example:

ctx.getPreviousReult().getResponseCode();

ctx.getPreviousResult().getResponseHeaders();

Here the output goes to file:

log.info(ctx.getPreviousResult().getResponseDataAsString());

log.info(ctx.getPreviousResult().getContentType());

log.info(ctx.getPreviousResult().getUrlAsString());