fugmag
September 24, 2014, 3:15pm
1
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
Excilys
September 24, 2014, 3:29pm
2
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”)
fugmag
September 24, 2014, 3:41pm
3
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!
Excilys
September 24, 2014, 3:49pm
4
fugmag
September 24, 2014, 3:59pm
5
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>
Excilys
September 24, 2014, 4:06pm
6
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).
fugmag
September 24, 2014, 4:17pm
7
Ok, but
.baseHeaders(“X-Token”, “1234asdf”)
does not work.
see the screenshot.
Cheers,
Magnus
Excilys
September 24, 2014, 4:23pm
8
As the doc pointer I previously sent states, baseHeaders takes a Map.
baseHeaders(Map(“X-Token” → “1234asdf”))
fugmag
September 24, 2014, 4:26pm
9
Great, thank you! I was not certain how to state “a map”.
Works now.
Excilys
September 24, 2014, 4:44pm
10
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