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

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;
    
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面