Gatling Load Test - Error:“HTTP response: status= 406 Not Acceptable ”

I’m new to Gatling tool load test.

Working on a small project on sentiment analysis on movie reviews. I am passing JSON data to RestAPI hosted in my local machine. I wanted to perform load test using gatling tool, here is my code,

class BasicSimulation extends Simulation {
val httpConf = http
.baseURL(“http://localhost:10050/sentiment”)
val scn = scenario(“test”)
.exec(http(“request_1”)
.post(“http://localhost:10050/sentiment”)
.body(StringBody("""{ “inputData”: “Amazing movie” }""")).asJSON)
.pause(7)
setUp(scn.inject(atOnceUsers(30)).protocols(httpConf)}

In Gatling tool test, getting no errors in HTTP request , but getting error in HTTP Response as follows, “HTTP response: status= 406 Not Acceptable” and

ResponseProcessor - Request ‘request_1’ failed: status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 406.

Server end receives http request without any exception and tried printing inputData too, which works fine. But only in HTTP response I’m getting "HTTP/1.1 406 Not Acceptable "

Thanks in advance.

You didn’t add any headers to your request - you most likely need to add an Accept header with the appropriate content type.

As follows (using your code snippet):

class BasicSimulation extends Simulation {
val httpConf = http
.baseURL(“http://localhost:10050/sentiment”)
val scn = scenario(“test”)
.exec(http(“request_1”)
.post(“http://localhost:10050/sentiment”)
.headers(myHeaders)

.body(StringBody("""{ “inputData”: “Amazing movie” }""")).asJSON)
.pause(7)
setUp(scn.inject(atOnceUsers(30)).protocols(httpConf)}

Where headers is a Map - example:

val myHeaders = Map(
“Content-Type” → “application/json”,
“Accept” → “application/json”
)

Barry

Thanks for the response,
I tried adding accept header with required content type. But still getting same error .

Can you get a request working in curl / postman? If so then simply evaluate the differences to work out what’s missing or incorrect in your request.

Solved the Issue.
Found serialization error is the issue behind this in my code.
Thanks Anyway.