本文介绍了HttpWebRequest的不及格证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用的HttpWebRequest 来访问REST服务,我有过凭据,请参阅下面code问题。我读过的NetworkCredential 不支持SSL,和我打HTTPS站点。有谁知道类似的NetworkCredential A类,不支持SSL的?

 乌里requestUri = NULL;
Uri.TryCreate(https://开头MyWebServer的/网页,UriKind.Absolute,出requestUri);
HttpWebRequest的要求=(HttpWebRequest的)HttpWebRequest.Create(requestUri);
的NetworkCredential NC =新的NetworkCredential(用户,密码);
request.Credentials = NC;
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse响应=(HttpWebResponse)request.GetResponse();


解决方案

如果您的服务器使用NTLM身份验证,你可以尝试这样的:

  CredentialCache CC =新CredentialCache();
cc.Add(
    新的URI(https://开头MyWebServer的/网页),
    NTLM
    新的NetworkCredential(用户,密码));
request.Credentials = CC;

I'm trying to use HTTPWebRequest to access a REST service, and am having problems passing credentials in, see code below. I've read that NetworkCredential doesn't support SSL, and I'm hitting an HTTPS site. Does anyone know of a class similar to NetworkCredential that does support SSL?

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();
解决方案

If your server uses NTLM authentication you may try this:

CredentialCache cc = new CredentialCache();
cc.Add(
    new Uri("https://mywebserver/webpage"), 
    "NTLM", 
    new NetworkCredential("user", "password"));
request.Credentials = cc;

这篇关于HttpWebRequest的不及格证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:13