HHDJSDNNM 2017-09-14 13:36 采纳率: 0%
浏览 3233

C# HttpWebRequest发送GET请求的问题

ServicePointManager.DefaultConnectionLimit = 500;
ServicePointManager.Expect100Continue = true;
ServicePointManager.CheckCertificateRevocationList = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
string url = @"https://login.wx2.qq.com/jslogin?appid=wx782c26e4c19acffb";
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url);
wRequest.Method = "GET";
wRequest.ContentType = "text/javascript";
wRequest.CookieContainer = CookiesContainer; //启用cookie
if (CookiesContainer == null)
{
CookiesContainer = new CookieContainer();
}
WebResponse wResponse = wRequest.GetResponse();
Stream stream = wResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default);

        string str = reader.ReadToEnd();   //url返回的值  
        MessageBox.Show(str);
        reader.Close();
        wResponse.Close();
 上面代码为什么在部分电脑上超时,手动打开网页没问题,求思路!





  • 写回答

3条回答 默认 最新

  • Go 旅城通票 2017-09-15 00:40
    关注

    添加using System.Security.Cryptography.X509Certificates;空间,然后添加下面的代码

         public static bool SecurityValidate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true;//直接确认,不然打不开,会出现超时错误
        }
    
    
    ////////////添加这句
    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(SecurityValidate);
    //////////////
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办