代碼在win7下沒有問題,在win10下怎么除錯都是超時,下面是代碼:
HttpWebRequest myRequest = null;
myRequest = (HttpWebRequest)WebRequest.Create(url.ToString());
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;//微信采用的是TLS12
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(CheckValidationResult);
}
//myRequest.ServicePoint.Expect100Continue = true;
//myRequest.AllowAutoRedirect = false;
myRequest.Method = method;
myRequest.ProtocolVersion = HttpVersion.Version10;
if(timeout)
myRequest.Timeout = 7000;
myRequest.KeepAlive = true;
myRequest.CookieContainer = backcookie;
myRequest.Headers.Add("Cookie", cookiesstr);
myRequest.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36";
myRequest.ContentType = (method == "POST" ? "application/json;charset=UTF-8" : "application/x-www-form-urlencoded");
if (method != "GET")
{
byte[] data = Encoding.UTF8.GetBytes(paramPost);
myRequest.ContentLength = data.Length;
using (Stream dataStream = myRequest.GetRequestStream())
{
dataStream.Write(data, 0, data.Length);
dataStream.Close();
}
}
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();//卡在這里,報錯超時
uj5u.com熱心網友回復:
微信的url可以正常訪問么?uj5u.com熱心網友回復:
網頁可以訪問,程式 (HttpWebResponse)request.GetResponse();這里就會超時,另外win7下運行沒有問題,win10下會超時uj5u.com熱心網友回復:
https 改為http 問題解決 ,不管那么多了,先這樣吧轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/119529.html
標籤:網絡通信
