Response code: 418 'I'm a teapot' in jmeter - json

I've been trying to test the API of restful-booker in Jmeter. But whenever I try to create a booking or Get a Booking by id I'm getting the HTTP response:418 'I'm a teapot'.If I try to access the URL in the browser it says the same. But when I run this in postman it does not give any kind of error. Also, it shows the correct response in Code Beautify. Really frustrating. Is there any way to resolve it?

If you're capable of successfully executing the request in postman (or whatever else tool) and not able to do it with JMeter most probably you're sending a different request.
Check out literally everything: URL, headers, body, etc. - all matters.
There are 2 approaches:
Use a 3rd-party sniffer tool like Fiddler or Burp to capture the requests from postman and JMeter and compare them for differences
Or just record the request from Postman using JMeter's HTTP(S) Test Script Recorder, JMeter will capture the request and generate relevant HTTP Request sampler and HTTP Header Manager

Problem is here: you forgot add accept: application/json in jmeter, postman automatically adds this setting.

Related

API POST response returning 400 response code in Jmeter

I am trying to create a test plan using jmeter.its for an API Post request, I have a header manager, bodydata, checked for spellings and the syntax seems to be correct. However, Im getting 400 response code with the following error shown in the attached image. Anyone with an idea how I can resolve this? Thank you. the error
Here is the request the request
The user doesn't have to be logged in, i have added a header manager, I have also noticed there header has a cookie value thats hard coded but it appears to be the same in every request. In the UI the API request returns 200 and thats what im expecting with the Jmeter script.
In its current form the question cannot be answered comprehensively.
HTTP Status Code 400 means that
The 400 (Bad Request) status code indicates that the server cannot or
will not process the request due to something that is perceived to be
a client error (e.g., malformed request syntax, invalid request
message framing, or deceptive request routing).
Check that your ${site} and ${csVersion} variables have their respective values using Debug Sampler and View Results Tree listener combination
Cross check headers sent by JMeter and by the "UI", the most important is Content-Type
Use a sniffer tool like Wireshark of Fiddler and capture the requests which are being sent by JMeter and the "UI", the requests must be exactly the same apart from dynamic parameters which need to be correlated
The issues was being caused by an anti-forgery cookie which was hard coded in the request.I used a regex to extract the value from a previous request and used a variable value from the regex to make sure the same value is being passed on to the request that was failing.

How to send a GET request with JSON body in JMeter?

I am facing some issues as JMeter doesn't take the JSON body passed as a parameter. I tried through postman and it was working fine but for Jmeter it is not working
I am expecting a response from get request with JSON body in Jmeter
We're not telepathic enough in order to suggest you how you can fix your "some issues" without knowing the details of the "issues"
JMeter can send the GET request with the JSON (or any other) body
If the request works in Postman and doesn't in JMeter most probably you're not sending the same requests, the most common mistake is that people forget to add a HTTP Header Manager configured to send correct Content-Type header.
Just use a 3rd-party sniffer tool to intercept requests originating from JMeter or Postman, identify the difference(s) and amend your JMeter configuration so the requests would be exactly the same. Alternatively just record the request from Postman using JMeter's HTTP(S) Test Script Recorder

JMeter to test java rest Api

How can i pass the json for post method if my json is like:
{
"REQUEST":{"REQUEST_BODY":{"Account_Name":"ak"}}
}
It gives me an error at time of parsing json value
In postman it run properly
In HTTP Request use Body Data tab and of course fill-in Server Name, Port Number, Path and Update Method if needed:
And under HTTP Request add a Header Manager:
And add to it required headers:
Note Content-type might be different for you.
If your request works in Postman you can just record it in JMeter:
Configure JMeter for recording, the fastest way is using JMeter Templates feature
From JMeter's main menu choose File - Templates - Recording - Create
Expand Workbench - HTTP(S) Test Script Recorder and click "Start
Configure Postman for recording. You can "tell" Postman which proxy server to use (JMeter in your case) via --proxy-server command-line argument
C:\Users\your_user_name\AppData\Local\Postman\app-x.x.x\Postman.exe --proxy-server=localhost:8888
Execute your request in Postman
JMeter will capture the request and store it under Test Plan - Thread Group - Recording Controller
References:
Apache JMeter proxy Step-by-step
How to configure Postman Native Client App to use an external proxy

Track navigation with jmeter

I try to make a stress test with jmeter: i set up jmeter proxy to record navigation and everythings is ok.
I have some problem with a page wich has a json request called by javascript: using the jmeter proxy this request doesn't works.
With firebug I can see that the response of json request is
{"error":{"msg":"couldn't parse request arguments","code":590}}
It seems that jmeter proxy modify the parameter request.
With this error, I cannot use this page: any suggest?
Thanks
Aldo
JMeter isn't able to execute JavaScript, you'll need to construct the request manually. Perhaps you'll need to get some parameter(s) from page source via Regular Expression Extractor. Once you figure out correct request make sure that you'll add Content-Type header application/json via HTTP Header Manager

How does HTTP and HTML Work Together?

The answer to this little question will clear everything up for me.
If have a form tag that has a Get method and an action of some random script.
When I hit the submit button on the page, the Get Method is sent to HTTP and HTTP is what appends the query string to the url, the HTTP then returns a 20X status if the response is good and a 40X is a bad response? And our action goes to our webserver to run the script?
HTTP is transport and HTML is content. The Form submit calls a GET or POST request on the server depending on the action defined for the HTML form. The Form's arguments are appended by the Browser's form logic to the HTTP request, depending whehter GET or POST is used, they are attached to the request URL or put into the request body.
Then the request is handled on the server and the result is returned by the server logic (which can be a CGI, some perl script, a J2EE application etc.).
The server seponds with a HTTP status code (where everything below 300 is a success, and everything above 399 is an error - see here:HTTP staus codes ).
You are sending your form's data via HTTP using the "get" request. HTTP is a protocol and not a server. Your request is handled by a server who knows how to handle the HTTP protocol, eg. Apache.
The server processes the data and sends back a response. As you mention there are different kind of responses. 404 is best known (document not found).
The script is not run on the server, it is run on the client (the browser).
HTML is the markup code that describes the structure of the page. Browsers interpet the HTML code they receive and construct your page from it. Check here for more details: Wikipedia: HTML
The HTTP is the protocol used by the browser to talk to the server. Check this for more details: Wikipedia again: HTTP