Hello,
your code should work as expected if:
The PreAuthenticate is set to true - In my test project I realized that the PreAuthenticate is always false.
The Credentials property contains required credentials - In my test project I realized that the Credentials is always null.
Please ensure that line request.Headers.Add("Authorization", ... was executed.
I suggest you to use one particular credential and if it works, then use Credentials.GetCredential() logic.
I also suggest you to do it like this:
request.Credentials = new NetworkCredential(username, password);
This will enables you to use other authentication mechanisms such as Negotiate or Ntlm automatically. However setting Authorization header explicitly works as well.
And the last comment of your code:
You can use either creator.Register(); or creator.Create(uri); Using both together has no meaning. Please note that when you execute creator.Register(); all subsequent creations of WebRequest class will create instances of Rebex HttpRequest (not only in DATA_CAPTURE_MANAGEMENT class, but everywhere in project).
So use it like this:
creator = new Rebex.Net.HttpRequestCreator();
creator.Register();
System.Net.WebRequest request = base.GetWebRequest(uri);
or like this:
creator = new Rebex.Net.HttpRequestCreator();
System.Net.WebRequest request;
switch (uri.Scheme)
{
case "http":
case "https":
// use Rebex HttpRequest to handle HTTP and HTTPS requests
request = creator.Create(uri);
break;
default:
// use default functionality to handle other requests
request = base.GetWebRequest(uri);
break;
}