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

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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用