1

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

Abdul Alim Shakir
  • 1,128
  • 13
  • 26

2 Answers2

0
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

Devarajan
  • 131
  • 1
  • 2
  • 12
  • I want to send the data " JSESSIONID=24BE2C5D2DA************************* " in a parameter named "Cookie" in the request header. My name of the variable is not 'JSESSIONID', it is 'Cookie'. I have also tried this. Somehow the 'Cookie' parameter can not be sent by the request header. – Abdul Alim Shakir Nov 24 '19 at 07:09
  • You are using Pre-Processor for setting Cookie data or not? If you are sending it with HTTP Request in Java code means the following code will help. postRequest.setHeader("Cookie", "JSESSIONID="+ vars.get("jSessionId")) – Devarajan Nov 25 '19 at 10:12
0

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

Eugen2222
  • 1
  • 1