ANTSLOAD 17 - Bug in AddCredentials

Brian DonahueBrian Donahue Posts: 6,590 New member
edited November 24, 2006 5:03AM in Knowledge Base
  • Date: 24 Nov 2006
  • Products affected: ANTS Load 1.7+
Background
ANTS Load allows you to add login credentials to an HTTP request using the AddCredentails method of the HttpRequest object. This method allows you to authenticate to a web server in your test script using a variety of methods. AddCredentials appends a header called Authorization to the list of headers sent with the request.

Issue
The AddCredentials method, when used with Basic authentication, must be invoked on every single request. The problem is that when AddCredentials is invoked multiple times in one script, the authorization header value is not cleared properly and at second and subsequent invokations, the method produces invalid credentials because it is appending the new credentials to the previous ones.

workaround
Until this can be addressed in a future release, there are some workarounds. One is to remove the authorization header before AddCredentials is used again. The other is to assign the header produced by AddCredentials to a variable and continue re-using it.

Example 1
WebClient.HttpRequest.AddCredentials(Authentication.AuthType.Basic, "RED", "brian", "[email protected]")
WebClient.Get("http://localhost/antsloadtutorialwebsite/employees.aspx")
WebClient.HttpRequest.Headers.Remove("Authorization")
        WebClient.HttpRequest.AddCredentials(Authentication.AuthType.Basic, "RED", "brian", "[email protected]")
WebClient.GET("http://localhost/antsloadtutorialwebsite/employee.aspx?id=6")

Example 2
Dim Authorization As String
        WebClient.HttpRequest.AddCredentials(Authentication.AuthType.Basic, "RED", "brian", "[email protected]")
        Authorization = WebClient.HttpRequest.Headers.Get("Authorization")
WebClient.Get("http://localhost/antsloadtutorialwebsite/employees.aspx")
WebClient.HttpRequest.Headers.Set("Authorization", Authorization)
        WebClient.GET("http://localhost/antsloadtutorialwebsite/employee.aspx?id=6")
Sign In or Register to comment.