Tuesday, June 26, 2012

401 - Unauthorized error in Web Performance test

Scenario:
1. In a Visual Studio Web Performance test, make call to a web service that requires credentials.
=> you will get 401 - Unauthorized error (if you did not specify credentials)

Solution:
1. Add a Header (for Basic authentication) to the web test request: Right-click on the call -> Add Header.

2. Add the following info:
Name: "Authorization"
Value: “Basic ” + encodeBase64 (“username:password”)

Use http://www.base64encode.org/ to encode username and password in the following format: "username:password".

It should look like this:

2 comments:

  1. Salut alina,

    ma lovesc de aceasi problema si am cateva intrebari: Ghilimelele sunt obligatorii ? si unde pot sa vad valuarea header-ului din timpul runtime ? tot ce pot sa vad, e valoarea pe care o dau eu sub forma sugerata, dar fara encodare

    Ms mult!

    ReplyDelete
    Replies
    1. Salut Andrei,

      Am mai updatat postul sa fie mai clar. Ghilimelele nu trebuie puse.
      Pasii sunt:
      1. Right-click pe un call catre un service -> Add Header.
      2. La Name pui Authorization.
      3. La Value pui Basic encodeBase64(username:password).
      Ar trebui sa arate ca in imaginea de pe blog.
      Trebuie sa introduci tu valoarea gata encodata. Poti sa introduci username:password aici: http://www.base64encode.org/ si vei obtine stringul encodat necesar.

      Sper sa fie de ajutor.

      Alina

      Delete