Add support for Basic Access Authentication in .NET RemoteWebDriver
The username and password of the Uri wasn't used by the HttpWebRequest.
Usage example
new RemoteWebDriver(new Uri("http://user:pass@example.com/wd/hub"), DesiredCapabilities.Chrome());
@@ -149,6 +149,13 @@ private static string GetTextOfWebResponse(HttpWebResponse webResponse)
private HttpResponseInfo MakeHttpRequest(HttpRequestInfo requestInfo)
{
HttpWebRequest request = HttpWebRequest.Create(requestInfo.FullUri) as HttpWebRequest;
+ if (!string.IsNullOrEmpty(requestInfo.FullUri.UserInfo) && requestInfo.FullUri.UserInfo.Contains(":"))
+ {
+ string[] userInfo = this.remoteServerUri.UserInfo.Split(new char[] { ':' }, 2);
+ request.Credentials = new NetworkCredential(userInfo[0], userInfo[1]);
+ request.PreAuthenticate = true;
+ }
+
request.Method = requestInfo.HttpMethod;
request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds;
request.Accept = RequestAcceptHeader;
