private void HandleAuthException(Exception ex, WebRequest client) { if (ex is WebException webEx && webEx.Response != null) { var headers = ((HttpWebResponse)webEx.Response).Headers; var doAuthHeader = PclExportClient.Instance.GetHeader(headers, HttpHeaders.WwwAuthenticate, x => x.Contains("realm")); if (doAuthHeader == null) { client.AddBasicAuth(this.UserName, this.Password); } else { this.authInfo = new AuthenticationInfo(doAuthHeader); client.AddAuthInfo(this.UserName, this.Password, authInfo); } } }