Using a header cookie to perform requests

Hello,

I was wondering if anyone could help with a problem I’ve been having.

Our application which uses oauth2, needs a header cookie passed in to perform stuff such as get/post/delete requests. I’m able to get the cookie via postman.

The cookie is in 3 parts

".AspNetCore.Cookies=XXX; "

“.AspNetCore.CookiesC1=YYY;”

“.AspNetCore.CookiesC2=ZZZ;”

In my API testing suite, using unirest, something as simple as this works:

String adminUserCookie = “.AspNetCore.Cookies=XXX; .AspNetCore.CookiesC1=YYY; .AspNetCore.CookiesC2=ZZZ”;

@Test
public void admin_get_records() {
Unirest.config().reset();
Unirest.config()
.enableCookieManagement(false);

HttpResponse response = Unirest.get(“https://myurl.com/record/index”)
.header(“Cookie”, adminUserCookie)
.asString();
assertEquals(200, response.getStatus());
}

The problem is with Gatling, I can’t get it to work. I left the code at this after trying multiple things:

def addCookie1() :ChainBuilder = {
exec(addCookie(Cookie(".AspNetCore.Cookies", “XXX”)))
}

def addCookie2() :ChainBuilder = {
exec(addCookie(Cookie(".AspNetCore.CookiesC1", “YYY”)))
}

def addCookie3() :ChainBuilder = {
exec(addCookie(Cookie(".AspNetCore.CookiesC2", “YYY”)))
}

def adminGetRecords() :ChainBuilder = {
exec(http(“Admin Get Records”)
.get(“https://myurl.com/record/index”)
.check(status.is(200))
}

Then under the scenario I built the chain. I tried adding the cookie in with the get request as well, but was obviously doing that wrong. Any help would be really appreciated.

Many Thanks,

David

but was obviously doing that wrong

Why? What is your problem exactly?

Hi Stéphane,

I’m getting a 404 instead of a 200 when doing the get request and trying to use the access cookie.

A couple of other things I’ve tried:

def adminGetRecords() :ChainBuilder = {
exec(addCookie(Cookie(".AspNetCore.Cookies", " XXX “)))
.exec(addCookie(Cookie(”.AspNetCore.CookiesC1", “YYY”)))
.exec(addCookie(Cookie(".AspNetCore.CookiesC2", “ZZZ”)))
.exec(http(" Admin Get Records “)
.get(” https://myurl.com/record/index ")
.check(status.is(200))
)
}

def adminGetRecords() :ChainBuilder = {
exec(http(" Admin Get Records “)
.get(” https://myurl.com/record/index ")
.header(“Cookie”, “.AspNetCore.Cookies=XXX; .AspNetCore.CookiesC1=YYY; .AspNetCore.CookiesC2=ZZZ;”)
.check(status.is(200))
)
}

Thanks,

David

The Gatling syntax is correct.
As of why your test doesn’t work is something that’s on your plate.

Try lowering the logging level in logback.xml, check the actual payloads and compare with what you have with unirest.