How to extract a cookie?

 
0 6 1,975
6 REPLIES 6

Not applicable

You can use extract variable policy and extract the cookie from header.

This normally comes as request.header.cookie

Can u please guide me step by step and also how cookie is extracted from header and do i need to use JS if so please share.

curl--location--request GET 'https://www.google.com' is input curl.

on calling google.com we get cookies

partial code is this:-

var goog = httpClient.get('https://www.google.com')

goog.waitForComplete
()var resp = goog.getResponse()
if(resp.status =200)
    {
    var cookie = resp.headers['Set-Cookie']
    context.setVariable('sCookie',/S=(.*);/.exec(cookie)[1])
    }
print('status '+ resp.status)
print('set-cookie '+ resp.headers['Set-Cookie'])
print('regex '+/S=(.*);/.exec(cookie))

How to proceed further tell me step by step which policy is to be used and the script too.

Not applicable

Ok, you are getting cookie in response header.

So, you can use response.header.set-cookie to get the cookie.

You can use an assign message policy in response and assign to a variable using Ref tag to response.header.set-cookie

You can use javascript as well in response flow. In the script use

var x= context.getVariable("response.header.set-cookie");

Extract variable policy will be required?

if you want a particular patter from that then you may need. if you want whole value then not required.