0
votes

I am new with JMeter. I am using apache jmeter 5.2 with Java 8. I want to send cookie data in a field name "Cookie" in the request header of a post request at the time of logging in a user to a website. The request header will like the following picture :

Cookie data

First of all, I am sending a get request to the server and holding cookie data using regular expression extractor and using the value in request header as a parameter named "Cookie". But unfortunately JMeter doesn't add that parameter with the request header. I have also used HTTP Cookie Manager. But I am getting cookie data in request body, but not in request headers.

I have already seen the following posts.

How to generate a cookie and send it in a request in Jmeter

2

2 Answers

0
votes
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("JSESSIONID",vars.get("jSessionId"),"${serveraddress}",false,0);
manager.add(cookie);

Try with the above code in Pre-Processor of the request.

Edit: Improve the Format

0
votes

After trying all the methods on google and not working, I just figured that I can do some tricks on it.

Step 1. Create a header manager and firstly add a header you want. Then in this value column, you just put: "Cookie: your cookie value" immediately after its value. Then save your project. Please refer to my figure below.

header setting

Step 2. Open your project (.jml) with text editor and find the content for your header manager. You can find the value for your header in 'stringProp name="Header.value"'. Type a enter before "Cookie: your cookie value" and delete all blanks between the previous value and cookie. Save your .jml with Ctrl +S and reopen your jml with Jmeter and test it. It should work!

jml setting

result