From 891010485737a78000425d94b508012380234b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20B=C3=A9trisey?= Date: Thu, 16 Mar 2017 16:30:31 +0100 Subject: [PATCH] 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()); Signed-off-by: Jim Evans --- dotnet/src/webdriver/Remote/HttpCommandExecutor.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs index 8941c8eabfadd..882645016b894 100644 --- a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs +++ b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs @@ -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;