0

I am using https protocol with 3 headers to test API. My test succeeds in postman but I get response code 401 ( unauthorized ) when setting up and running in jmeter. I’m using same value for header parameter in postman and jmeter.

This is my request in jmeter:

POST https://url

POST data:
room_id=id

[no cookies]

Request Headers:
Connection: keep-alive

token: token

member_id: id

Content-Type: application/x-www-form-urlencoded

Content-Length: 32

Host: host

User-Agent: Apache-HttpClient/4.2.6 (java 1.5)
2
  • Can you paste exact HTTP request sent by POSTMan? This way you could compare how it differs from request sent by JMeter.
    – dzieciou
    Commented Jan 15, 2016 at 8:27
  • simple solution is try recording controler, it automatically adds header manager and all other required stuff, then you will come to know what you have missed Commented Jun 9, 2017 at 11:19

3 Answers 3

3

I will suggest you to use latest version of Jmeter i.e. 4.0 in which concept of workbench is eliminated and everything is under Test plan now.Solution of above mentioned problem is to add HTTP Cookie Manager with default values.

For reference check here.

1

It might be the case when application expects one more header which is "Authorization" (i.e. it is added when browser asks for credentials with popup). So if your API endpoint assumes a form of username/password authentication - provide the credentials via HTTP Authorization Manager. See How to Use HTTP Basic Authentication in JMeter guide for example usage.

I do not like your Content-Type as well. For API I would rather expect it to be application/json or application/soap+xml. So double check this bit as well and add relevant Content-Type header via HTTP Header Manager

0

I think you should revisit your script and check that you're having HTTP Header Manager in each request with the Authorization token. Also, you can change the content type to application JSON as this is REST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.