C# 微信模拟登录访问https://wx.qq.com 就 HttpWebRequest.GetResponse()出错 基础连接已经关闭: 发送时发生错误。

baidu_33198489 2015-11-30 05:36:22
winform 获取https://wx.qq.com/
自己电脑上开发完成后交给客户后 客户的某些电脑 就会出现这样的 错误
基础连接已经关闭: 发送时发生错误。

出现问题的电脑集中在 win7 64位系统上 (XP 32位的都正常)

但是我自己开发的电脑也是2008R2 64位的 可以正常访问


原因一直找不到 一开始怀疑客户电脑是 ghost版的有问题

为了重现这个错误 我弄了台笔记本电脑全新安装了 2008R2 64 写了最简单的一段代码
结果也报这样的错误 但是用浏览器请求这个网址https://wx.qq.com/却一切正常



static void Main(string[] args)
{

string url = "https://wx.qq.com"; //<-- 其他https 的我都能获取到 比如 https://mp.weixin.qq.com
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; //<- 这里改成Ss3 肯定不行
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
myReq.ProtocolVersion = HttpVersion.Version11;
myReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36";
HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse(); //<-- 这里就报错了
Stream resStream = myRes.GetResponseStream();
StreamReader strReader = new StreamReader(resStream);
string resStr = strReader.ReadToEnd();
Console.WriteLine(resStr);
Console.Read();
}

private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true; //总是接受
}







而其他的 https 的网址都正常 比如 淘宝的(https://login.taobao.com/) 或者 微信公众号的(https://mp.weixin.qq.com) 都能获取返回值 唯独这个 wx.qq.com 不行

通过搜索 也看过这个 http://bbs.csdn.net/topics/390982848 他的解决方式是
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls

但是对我这边也无效

我也看不出这个网址的证书和其他的有什么不同





尝试动作
关闭防火墙
ServicePointManager.DefaultConnectionLimit 设为512
ServicePointManager.CheckCertificateRevocationList = false;
都无效


有没人再提示些新的思路让我找找原因 是不是电脑哪里还要设置下?

分不够这边 还有40分 那个号分
http://bbs.csdn.net/topics/391864934


...全文
9037 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
yule5xiang0 2017-03-07
  • 打赏
  • 举报
回复
跟我遇到的问题一样 解决了分享一下啊
憧憬z 2016-01-20
  • 打赏
  • 举报
回复
我做淘宝也遇到这个问题,顺利解决。 因为用的是TLS 1.2,如果是.net 4.5 可以直接设置,.net4.0设置如下:

req.ProtocolVersion = HttpVersion.Version11;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;//SecurityProtocolType.Tls1.2;
如果.net 2.0 参考:http://blog.csdn.net/atceedsun/article/details/50443657 结贴吧
hb32123 2016-01-19
  • 打赏
  • 举报
回复
楼主,请问你是怎么解决的?我现在遇到和你一样的问题,头都憋大了!
aspvfp 2015-12-23
  • 打赏
  • 举报
回复
问题解决..
baidu_33198489 2015-12-05
  • 打赏
  • 举报
回复
唉 和wx2.qq.com 没关系 第一步请求就出错了 后面就算访问wx2.qq.com也是错的 有人说.NET框架底层的WebRequest是用IE的wininet.dll来进行网络请求的 我特地升级 IE11 测试 也不行 降到IE8也是这个错误
失落的神庙 2015-12-03
  • 打赏
  • 举报
回复
引用 10 楼 baidu_33198489 的回复:
.
都能用啊。 我也做了。都好好的。你什么功能不能用了?
baidu_33198489 2015-12-03
  • 打赏
  • 举报
回复
引用 9 楼 wawd74520 的回复:
[quote=引用 8 楼 baidu_33198489 的回复:]
没那么复杂。我给你个参考地址 http://blog.csdn.net/macwhirr123/article/details/46545333[/quote] 功能我都写完了 客户已经在用了 现在就是有部分机用不了 比较尴尬. 但是你没发现里面需要抓包访问连接的 都是https 的.
失落的神庙 2015-12-03
  • 打赏
  • 举报
回复
引用 8 楼 baidu_33198489 的回复:
没那么复杂。我给你个参考地址 http://blog.csdn.net/macwhirr123/article/details/46545333
baidu_33198489 2015-12-03
  • 打赏
  • 举报
回复
引用 7 楼 wawd74520 的回复:
没事 http可以做的。试试吧。有些要来路的用https://wx.qq.com 等。
不行啊 跳过了登录 但是后面获取内容发送内容 都是要用 https 现在让客户把不能用的重装系统 心里7上8下的 也不知道重装后的 能不能用.. 很想知道HttpWebRequest.GetResponse() 底层的原理 有调用那些系统的资料 我总感觉系统哪里没设置好导致的.
失落的神庙 2015-12-03
  • 打赏
  • 举报
回复
引用 12 楼 baidu_33198489 的回复:
因为有些时候用的是 wx2.qq.com 你自己留意下看看。
baidu_33198489 2015-12-03
  • 打赏
  • 举报
回复
引用 11 楼 wawd74520 的回复:
[quote=引用 10 楼 baidu_33198489 的回复:].
都能用啊。 我也做了。都好好的。你什么功能不能用了?[/quote] 简单说就是某些 win7 64位 的机器 使用的时候会抛出 "基础连接已经关闭: 发送时发生错误。" 异常 我自己现在的笔记本电脑是2008 64位的就会这样 而我的台式机 也是同样的系统 一切正常
失落的神庙 2015-12-02
  • 打赏
  • 举报
回复
没事 http可以做的。试试吧。有些要来路的用https://wx.qq.com 等。
baidu_33198489 2015-12-02
  • 打赏
  • 举报
回复
引用 5 楼 wawd74520 的回复:
http://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN 试试这个 http://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN
http 的访问没任何问题 但是 如果是 https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN 就异常了..
失落的神庙 2015-12-01
  • 打赏
  • 举报
回复
http://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN 试试这个 http://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN
baidu_33198489 2015-12-01
  • 打赏
  • 举报
回复
引用 3 楼 wawd74520 的回复:
额。不对不对。 应该是写成这样。 return outdata;
在可以的电脑上 可以获取 但是在不行 报了个异常 连接超时
失落的神庙 2015-11-30
  • 打赏
  • 举报
回复
额。不对不对。 应该是写成这样。 return outdata;
失落的神庙 2015-11-30
  • 打赏
  • 举报
回复
return myResponse.ResponseUri.ToString(); //string outdata2 = myResponse.Headers["Location"]; //return outdata2; 自己用的时候 注意把下面两句取消注释。 上面那句注释
失落的神庙 2015-11-30
  • 打赏
  • 举报
回复
1.http://wx.qq.com/ 2.
    public string GetUrl(string url, Encoding Ec,string refstr="")
        {

            try
            {

                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url.ToString());

                if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    ServicePointManager.ServerCertificateValidationCallback =
                            new RemoteCertificateValidationCallback(CheckValidationResult);
                }
                //myRequest.ServicePoint.Expect100Continue = true;
                //myRequest.AllowAutoRedirect = false;
                myRequest.Method = "GET";
                myRequest.Referer = refstr;
                myRequest.Timeout = 5000;
                myRequest.KeepAlive = true;
                myRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36";
                myRequest.Headers["Cookie"] = CookieStr;
                myRequest.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Ec);
                string outdata = reader.ReadToEnd();
                reader.Close();

                return myResponse.ResponseUri.ToString();

                //string outdata2 = myResponse.Headers["Location"];
                //return outdata2;
            }
            catch
            {
                return string.Empty;
            }
        }

 private bool CheckValidationResult(object sender,
        X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true;// Always accept
        }

try

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧