日期:2014-05-16  浏览次数:20538 次

REQUEST HTTPS加证书的权限问题,求教
HTTPS,加了证书请求,但远程服务器返回。远程服务器返回错误: (403) 已禁止。

但使用chrome请求,并且使用证书能正常访问HTTPS链接,也能返回数据。

不知道.NET程序为什么不行,以下是c#代码,证书路径是对的。


            ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidate;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            Uri uri = new Uri(@url);
            HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;

            InstallCertificate(clientP12_Path, clientP12PassWord, StoreLocation.CurrentUser, StoreName.My);
            X509Certificate cer = new X509Certificate(clientP12_Path, clientP12PassWord);

            request.ClientCertificates.Add(cer);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "post";
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Proxy = null;

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                responseText = reader.ReadToEnd();
            }
            return responseText;


安装证书的程序


       // 导入证书
        private static bool InstallCertificate(string certFilePath, string password, StoreLocation location, StoreName storeName)
        {
            try
            {
                if (!File.Exists(certFilePath))
                {
                    return false;
                }
                byte[] certData = File.ReadAllBytes(certFilePath);