开发者

new X509Store(StoreName.My, StoreLocation.CurrentUser) hasn't any certificate

This function for sending data on server, when server had HTTP protocol everything was good, but HTTP protocol was changed on HTTPS and I got a problem, I was trying update my method, but my store (X509Store) have no certificate.

How should look this method?

static public List<object> SendRequestCook(string textRequest, string url, string referer, CookieContainer cooks, string metod, string proxy)
    {
        try
        {

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));



            X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly);

            X509Certificate2Collection certs =
              store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            request.ClientCertificates.Add(certs[0]);






            System.Net.ServicePointManager.Expect100Continue = false;
            byte[] byteArray = Encoding.UTF8.GetBytes(textRequest);

            request.Method = "POST";
            request.ReadWriteTimeout = int.MaxValue;
            request.CookieContainer = cooks;
            //request.ProtocolVersion = HttpVersion.Version11;
            request.ContentLength = textRequest.Length;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
            request.Headers.Add("Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7");
            request.UserAgent = "Mozilla/4.0";
            request.KeepAlive = true;
            request.Referer = re开发者_开发技巧ferer;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(byteArray, 0, textRequest.Length);


            HttpWebResponse response = (HttpWebResponse)request.GetResponse();


            Stream responseStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(responseStream, enc);
            List<object> list = new List<object>();
            list.Add(cooks);
            string currResponse = readStream.ReadToEnd();
            list.Add(currResponse);
            list.Add(metod);
            readStream.Close();
            response.Close();

            return list;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            return SendRequestCook(textRequest, url, referer, cooks, metod, "");
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜