'403 forbidden error in jmeter but api works fine in postman

I have an API that is running in GET method. It works fine in postman with 200 status code. But when I try to run the API in jmeter it throws 403 forbidden error. I have configured the debug sampler and tried to re-run the test. The debug sampler passed with 200 but http request still fails.

  1. I have tried to correlate but even that fails.
  2. I removed the port number from the HTTP request, it still fails.
  3. I have added the authorization manager and enter the username and password still fails.
  4. HTTP cookie manager and cache manager added in the script.


Solution 1:[1]

As per HTTP Status Code 403 description

The HTTP 403 Forbidden client error status response code indicates that the server understood the request but refuses to authorize it.

This status is similar to 401, but in this case, re-authenticating will make no difference. The access is permanently forbidden and tied to the application logic, such as insufficient rights to a resource.

Most probably you have inconsistencies between requests originated from Postman and from JMeter.

There are 2 possible causes:

  1. You failed to configure JMeter's HTTP Request sampler properly. Given your request works fine in Postman you can try to record it using JMeter's HTTP(S) Test Script Recorder

    • Prepare JMeter for recording. The easiest way is going for JMeter Templates Feature

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

      • On Settings page set proxy host to 127.0.0.1 and port to 8888

        enter image description here

    • Execute the request in Postman

  2. Postman uses specific Authorization header which cannot be recorded and replayed. Look into Authorization tab for the request and check which one is used, once you figure out - implement the same in JMeter:

    enter image description here

Solution 2:[2]

Status Code 403 means you are not authorized to access it, so Ensure you are using the right Authorization for your GET call.

Solution 3:[3]

Add cookie manager in jmeter http sampler.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitri T
Solution 2 Karmic Coder
Solution 3 vijayv