110,566
社区成员
发帖
与我相关
我的任务
分享
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; //总是接受
}
req.ProtocolVersion = HttpVersion.Version11;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;//SecurityProtocolType.Tls1.2;
如果.net 2.0 参考:http://blog.csdn.net/atceedsun/article/details/50443657
结贴吧 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