求助 用HttpWebRequest访问微信登录接口超时

yule5xiang0 2017-03-06 09:49:59
代码在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();//卡在这里,报错超时
...全文
339 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yule5xiang0 2017-03-29
  • 打赏
  • 举报
回复
https 改为http 问题解决 ,不管那么多了,先这样吧
江南小鱼 2017-03-07
  • 打赏
  • 举报
回复
微信的url可以正常访问么?
yule5xiang0 2017-03-07
  • 打赏
  • 举报
回复
网页可以访问,程序 (HttpWebResponse)request.GetResponse();这里就会超时,另外win7下运行没有问题,win10下会超时

4,356

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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