2

For some reason

http("Update WishList")
.put("/api/update/${id}")
.header("Accept", "application/json;v=1")
.body(ELFileBody("bodies.json")).asJSON
.check(status.is(200))

causes > status.find.is(202), but actually found 406

But I know the service expects "application/json;v=1"

Checked the actual requests with Fiddler and found that the Accept header is "application/json" instead of "application/json;v=1"

Am I missing something?

Lenar
  • 419
  • 4
  • 19

2 Answers2

3

The purpose of the asJSON construct is to automatically force the Accept header of the request to application/json, hence, overriding your initial header.

Just remove asJSON and it should be alright.

notdryft
  • 163
  • 7
  • I just looked at ```asJSON``` in ```RequestBuilder.scala``` and found that it only sets headers (and overrides in my case). So @notdryft you're right ```def asJSON: B = header(HeaderNames.Accept, RequestBuilder.JsonHeaderValueExpression).header(HeaderNames.ContentType, RequestBuilder.JsonHeaderValueExpression)``` – Lenar Sep 25 '18 at 18:13
0

Try out the following:

var httpConf = http.baseURL("http://example.com")
.header("Accept", "application/json;v=1")

var testSetup = setUp(testScenario.inject(virtualUsers).protocols(httpConf))

For me it sends the relevant header:

Gatling Taurus Header

Gatling version is 2.3.0


The configuration was generated by Taurus tool using the following YAML syntax:

execution:
- executor: gatling
iterations: 1
concurrency: 1
ramp-up: 1
hold-for: 1
scenario: some_scenario

scenarios:
some_scenario:
default-address: example.com
headers:
Accept: application/json;v=1
requests:
- url: /
      follow-redirect: false
Dmitri T
  • 159,985
  • 5
  • 83
  • 133