此功能用于在服务器上发送数据,当服务器具有HTTP协议时一切都很好,但HTTP协议在HTTPS上更改我遇到了问题,我正在尝试更新我的方法,但我的商店(X509Store)没有证书。
应该怎么看这个方法?
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 = referer;
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, "");
}
}