REST API testing with gatling

Hello everyone,
I am trying to test REST API using gatling. But I am getting “status.find.is(200), but actually found 400”. It’s for POST scenario. I have body parameters. So I configured “Headers and body”. please help me ASAP. I couldn’t figure out what went wrong in this.

package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class BasicSimulation1 extends Simulation {

val httpConf = http.baseURL(“http://192.168.0.10:23180/highresvu”)
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”) // Here are the common headers
.doNotTrackHeader(“1”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.acceptEncodingHeader(“gzip, deflate”)
.userAgentHeader(“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36”)

val headers_10 = Map(“Content-Type” → “application/xml”)
// Note the headers specific to a given request

val scn = scenario(“My Scenario”) // A scenario is a chain of requests and pauses
.exec(http(“Top Speed”)
.post("/topspeed")
.headers(headers_10)
.body(StringBody("""{“highResVehicleUtilization”:{"-xmlns": “http://wirelesscar.com/highresvu/highresvehicleutilization/1_0",“request”:{“vehicleDetails”:{"vin”: “RIGUD000000000057”,“chassisId”: “RIGUD-000057”},“driveSessions”:{ “driveSessionId”: “1460453954” },“duration”:{“fromDate”: “2016-05-27T10:30:10.000Z”,“toDate”: “2016-05-16T10:55:10.000Z”}}}}"""))
.check(status.is(200)))

setUp(scn.inject(atOnceUsers(100)).protocols(httpConf))
}

I’m new to Gatling, but the one thing I do differently is a payload. Try
.body(StringBody("{“highResVehicleUtilization”:{"-xmlns": “http://wirelesscar.com/highresvu/highresvehicleutilization/1_0”,“request”:{“vehicleDetails”:{“vin”: “RIGUD000000000057”,“chassisId”: “RIGUD-000057”},“driveSessions”:{ “driveSessionId”: “1460453954” },“duration”:{“fromDate”: “2016-05-27T10:30:10.000Z”,“toDate”: “2016-05-16T10:55:10.000Z”}}}}")) or define payload variable and convert it to json before executing scenario (like described here).

Basically your API returns a 400 instead of the expected 200. Therefore you need to check if your request is really something that is expected on your API