4
votes

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:

1

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!

2
Also, please update your question with Jmeter logAdnan
Do you have a working curl for your request, if you do please share it with usQuakeCore
Add a View Result Tree (right click on your thread group > Add > Listener > View Result Tree, then try to send your request, you will find the request under the result tree, with request/response...QuakeCore
Have updated with the logs as suggested by Adnan and @QuakeCore ,Isee a 500 error which is what my server returns anyway.Arun Krishnan
500 response indicates a general failure at the server side, I would be checking the server logs if I were uQuakeCore

2 Answers

0
votes

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

References:

0
votes

By seeing the image you have attached you are missing / in the path.

the path should be /registerMobileUsingCode

  1. if it is working fine from POSTMAN, then your port 8080 is fine.
  2. Can you please confirm what is the data type of your request? looks like languageId is integer so you should be using languageId: 1, instead of languageId: "1". The integer should not be double quotes.