C# HTTPS HttpWebRequest 需要 Framework4.5.2以上版本

C# HTTPS HttpWebRequest 需要 Framework4.5.2以上版本

public static string GetHtmlSource(string Url)

{

try

{

if (Url.StartsWith("https"))

{

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

}

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());

httpWebRequest.ServicePoint.Expect100Continue = true;

httpWebRequest.Method = "GET";

httpWebRequest.Timeout = 30000;

httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";

httpWebRequest.KeepAlive = true;

HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

string result = "";

using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8))

{

result = streamReader.ReadToEnd();

}

return result;

}

catch (Exception ex)

{

return ex.Message;

}

}

批量修改文件名精灵 2024年最新版
批量修改文件名称、文件夹名称

免费使用 功能无限制

方便快捷,支持正则表达式、无需安装功能齐全、支持定制无广告、无插件,放心使用。

免费下载 百度网盘
本站中所有的计算器的计算结果仅供参考,本站对此结果的准确性不承担任何责任,实际数额以银行/保险公司/国家相关机构确认的结果为准。
在线客服QQ:543690914,备案号: 苏ICP备15037649号-33。东海县白塔埠镇佳诚电脑经营部版权所有。