Jmeter - POST API not working

Arun Krishnan Source

I am new to Jmeter and have been struggling to get it working to test my POST API. It works fine for a GET API call where I pass the parameters through the Parameters tab.

Details here:

server name: localhost port: 8080 path /registerMobileUsingCode

In the request body, I am sending the following:

{ "clientName": "DemoOrg", "code": "9880007615", "languageId": "1" }

My Jmeter setup looks like this:


And my HTTP Request Header looks like this:

Request Header details

The API is in production and works fine with postman.

I am just unable to get it working through JMeter. It is obvious that I am doing something wrong but can't figure out what despite having spent a considerable amount of time Googling for solutions.

Any help would be much appreciated.

UPDATE - 1 - Updated with jmeter log as suggested

Thread Name: Thread Group 1-1 Sample Start: 2017-08-09 17:03:41 IST Load time: 1604 Connect Time: 1525 Latency: 1604 Size in bytes: 399 Sent bytes:251 Headers size in bytes: 213 Body size in bytes: 186 Sample Count: 1 Error Count: 1 Data type ("text"|"bin"|""): text Response code: 500 Response message: Server Level Exception encountered

Response headers: HTTP/1.1 500 Server Level Exception encountered Date: Wed, 09 Aug 2017 11:33:43 GMT Access-Control-Allow-Origin: * Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(9.2.16.v20160414)

HTTPSampleResult fields: ContentType: application/json DataEncoding: null

UPDATE-2 - Using Postman and JMeter Recorder

As suggested by @Dimitri T, I downloaded the Linux version of Postman and started it with --proxy-server=localhost:8888.

I was now able to make a Postman request and capture the request in JMeter. Here is what the request looked like:

Jmeter capture of a Postman Request

As you can see, nothing radically different from what I did. However, this DOES work! So hurray!



answered 7 months ago user7294900 #1

You need to uncheck use multipart/form-data for post in HTTP request.

multipart override Content-Type header see HTTP Request.

When using multipart/form-data, this suppresses the Content-Type and Content-Transfer-Encoding headers; only the Content-Disposition header is sent.

answered 7 months ago Dmitri T #2

If your application works fine with Postman the fastest and the easiest way of building JMeter test plan will be just recording it using JMeter's HTTP(S) Test Script Recorder.

  1. Prepare JMeter for recording (you can do it in a few clicks via JMeter Templates Feature)

    • from JMeter's main menu choose File -> Templates -> Recording and click "Create"
    • Expand Workbench - HTTP(S) Test Script Recorder and click "Start"
  2. Prepare Postman for recording

    • In order to "tell" Postman to use JMeter as a proxy you need to provide --proxy-server parameter to it like:

      C:\Users\YOUR_USER_NAME\AppData\Local\Postman\app-x.x.x\Postman.exe --proxy-server=localhost:8888
  3. Execute your requests in Postman

  4. JMeter will capture requests, convert them into HTTP Request samplers and store them under Test Plan -> Thread Group -> Recording Controller


comments powered by Disqus