我们在 IIS6 中创建了一个证书,并将其应用于使用 SSL 的站点。现在,我们之前使用的相同程序将无法正常工作。据我了解,c# 透明地支持 HTTPS,所以我相信它必须使用“不受信任”的证书。关闭代理设置后(收到 403 禁止错误),我收到“无法为 SSL 建立信任关系”
我尝试了一些解决方法,例如将默认证书策略与验证黑客交换,但它已经很老了,我仍然遇到同样的错误。
下面是我的发帖方法。
try
{
HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
HttpWebRequest.DefaultCachePolicy = policy;
byte[] buffer = Encoding.UTF8.GetBytes(postData);
//Initialisation
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.Timeout = 10000;
//method is post
if (useproxy == "ON")
{
WebProxy myProxy = new WebProxy();
// Create a new Uri object.
Uri newUri = new Uri(proxy);
// Associate the new Uri object to the myProxy object.
myProxy.Address = newUri;
WebReq.Proxy = myProxy;
}
WebReq.KeepAlive = false;
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer
WebReq.ContentLength = buffer.Length;
Stream PostData = WebReq.GetRequestStream();
//write, and close.
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
//Get the response handle
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);
//Do not worry about response!.
//read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
vystup = _Answer.ReadToEnd();
if (vystup != "OK")
{
}
}
catch (WebException ex)
{
Console.WriteLine(ex);
}
证书或我的应用程序或 IIS 中是否有任何解决方法可以解决此问题?大概是它的 C# 不信任证书,但这是我第一次尝试 Https。
欢迎任何信息。