我试图用来HTTPWebRequest访问REST服务,并且在传递凭据时遇到问题,请参见下面的代码。我读过,NetworkCredential它不支持SSL,而且我正在访问一个HTTPS网站。有谁知道类似的类NetworkCredential支持SSL?
HTTPWebRequest
NetworkCredential
Uri requestUri = null; Uri.TryCreate("https://mywebserver/webpage", UriKind.Absolute, out requestUri); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri); NetworkCredential nc = new NetworkCredential("user", "password"); request.Credentials = nc; request.Method = WebRequestMethods.Http.Get; HttpWebResponse response = (HttpWebResponse)request.GetResponse();
如果您的服务器使用NTLM身份验证,则可以尝试以下操作:
CredentialCache cc = new CredentialCache(); cc.Add( new Uri("https://mywebserver/webpage"), "NTLM", new NetworkCredential("user", "password")); request.Credentials = cc;