0
votes

I am trying jmeter for the first time. I have to load test a site that has authentication control using Apache htpasswd. I tried setting up the http Authorization manager, but i keep getting this error

Headers size in bytes: 291 Body size in bytes: 491 Sample Count: 1 Error Count: 1 Response code: 401 Response message: Authorization Required

I have given the site name, username, password given in the Authorization manager. Am i missing anything?

2

2 Answers

0
votes

Are you sure that it's really Basic authentication? How do you know? What happens if you inject username and password into URL as

http://username:password@site/path

If result will differ from 401 you could try providing Base URL (including the path) along with credentials.

See How to use HTTP Basic Authentication in JMeter guide for more details on how to properly configure HTTP Authorization Manager for Basic authentication challenge.

Just in case if anything goes wrong you can also use HTTP Header Manager. Looking into HTTP Request details, Basic HTTP Authentication results in the following HTTP Header:

  • Name: Authorization
  • Value: Basic [Base64-encoded username:password] string

So you can construct proper authorization header as follows:

  1. Add a HTTP Header Manager to your plan
  2. Put "Authorization" into "Name" field
  3. Put "Basic " into value field (mention space after basic"
  4. Now you need to know Base64-encoded value of username and password pair separated by colon. In order to know this
    • navigate to https://www.base64encode.org/
    • put your credentials as "username:password" (without quotes) into form and click "Encode" button
    • append the resulting encoded value to HTTP Header Manager's "Value" stanza, after "Basic "

Hope this helps.

0
votes

Thanks! that solution

http://username:password@site/path 

worked. It actually gave me an invalid character error for ":" and I had to replace : with %3A (http://en.wikipedia.org/wiki/Percent-encoding) and it worked. Thanks again!