Adding an .authorizationHeader as value/pair?

My request Works from Firefox RESTClient. See screenshot. The request needs a token called X-Token with value 1234asdf.
`

Request example:

— request —

GET https://ua.gaylord.us/user/profile HTTP/1.1

Accept-Encoding: gzip,deflate

X-Token: 1234asdf

Host: ua.gaylord.nus

— response body —

{

“resultCode”: “SUCCESS”,

“errorCode”: null,

“errorMessage”: null,

“profile”: {

“fullName”: “TestFirstName TestMiddleName TestLastName”,

“memberships”: [ {

“name”: “UA Gold Partner”,

“number”: “123-456-123-123”,

“scanNumber”: “123-456-123-123”

}]

}

}

`
However, in Gatling I try this:

val httpConf = http .baseURL([https://us.gaylord.us](https://us.gaylord.us)) .acceptEncodingHeader("""gzip,deflate""") .authorizationHeader("""X-Token:1234asdf""") val scn = scenario("Scenario")

And get the same error as I get when removing the token from Firefox RESTCleient:

`

{"resultCode":"PERMANENT_ERROR","errorCode":"UNEXPECTED_SERVER_ERROR","errorMessage":"Missing header 'X-Token' for method parameter type [java.lang.String]"}

`

My questions is:

How do I add a token in Gatling as I do in Firefox RESTClient? I guess I need to spesify name=X-Toekn and value 1234asdf ? But what is the syntax?

Cheers,

Magnus

Well…
Authorization is not a concept here, it’s the name of a HTTP header: Authorization.

So what you’re doing here is sending:
Authorization: X-Token:1234asdf

What you want here is to set a specific header named “X-Token”, so that would be:
.header(“X-Token”, “1234asdf”)

Ok,
But when I do that I get the error in IntelliJ that .header connot be resolved. Se screendump.
Do I need to import something?

Thanx!

Ha sorry, that’s baseHeaders: http://gatling.io/docs/2.0.0-RC5/http/http_protocol.html?highlight=httpprotocol#http-headers

There’s room for improvement here. Working on it: https://github.com/gatling/gatling/issues/2237

Ok thanks.
Then I need to upgrde my Gatling Version right. When this fix is shipped?

My pom states now:

<gatling.version>2.0.0-RC4</gatling.version>
<gatling-highcharts.version>2.0.0-RC4</gatling-highcharts.version>

No, you can use existing “baseHeaders”. Just that it will be deprecated in RC6 in favor of “headers” and will be removed in 2.1 (several months away).

Ok, but
.baseHeaders(“X-Token”, “1234asdf”)
does not work.
see the screenshot.

Cheers,
Magnus

huh2.jpg

As the doc pointer I previously sent states, baseHeaders takes a Map.

baseHeaders(Map(“X-Token” → “1234asdf”))

Great, thank you! I was not certain how to state “a map”.
Works now.

We do our best to progressively add more examples for people who are not familiar with Scala syntax…
Doing our best…

https://github.com/gatling/gatling/commit/93b80202523ccc41fdbc46cb022564ad7cb43e2b