3

Hi actually I want to test web service using Jmeter. but I am stuck when I want try to get response message from http request. actually I want to get the response message from beanshell post processor. How should I do to get the response code?

Hendrione
  • 225
  • 1
  • 5
  • 18
  • the question is not very clear. can you please add what you tried (Screenshots) and what is expected?. If you want get the response message, you can use the following code "String msg = .getResponseMessage(); log.info(msg);" in BeanShell post-processor – Naveen Kumar R B Nov 15 '16 at 11:50
  • typo in the code in above comment. try "String msg = SampleResult.getResponseMessage(); log.info(msg);" – Naveen Kumar R B Nov 15 '16 at 12:08

2 Answers2

5

You can also use context(ctx) variable to get the previous result data:

ctx.getPreviousResult().getResponseCode();
ctx.getPreviousResult().getResponseHeaders();
ctx.getPreviousResult().getResponseData();
Svp57
  • 308
  • 2
  • 13
  • thank you. it works too... it shoild be alternate way to get responsedata – Hendrione Nov 16 '16 at 07:44
  • how to get the required header from response header ? i have 2 set-cookie values ex: set-cookie: _csrf=XSASEDDDS;path=/ set-cookie: X-MY-CSRF=ABcnsfdgsg;path=/ – sravan ganji Apr 17 '19 at 18:49
2

It is as simple as

prev.getResponseMessage();

where prev is a shorthand to parent SampleResult class

Demo:

Beanshell Response Message Demo

See How to Use BeanShell: JMeter's Favorite Built-in Component article for more information on using Beanshell in JMeter

jwigley
  • 93
  • 7
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • 3
    thank you, it works. but I use this method to get the response message `prev.getResponseDataAsString()` – Hendrione Nov 16 '16 at 07:43