public void MakeHtml()
{
try
{
//动态页面网址
string strUrl = "https://www.psacloud.com/product/Detail/Default.aspx?ContentID=123";
//要存放静态网页的路径
string filePath = "/product/";
//物理完整路径
string toFileFullPath = HttpContext.Current.Server.MapPath(filePath);
//检查是否有该路径没有就创建
if (!System.IO.Directory.Exists(toFileFullPath))
{
System.IO.Directory.CreateDirectory(toFileFullPath);
}
filePath = filePath + "index.html";
if (File.Exists(System.Web.HttpContext.Current.Server.MapPath(filePath)))
{
File.Delete(System.Web.HttpContext.Current.Server.MapPath(filePath));
}
//创建请求
//如果访问的地址是带证书的https,需要加上这句话,证书认证
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
HttpWebRequest Dd_gUrl = (HttpWebRequest)WebRequest.Create(strUrl);
Dd_gUrl.UseDefaultCredentials = false;
HttpWebResponse WebRe = (HttpWebResponse)Dd_gUrl.GetResponse();
Stream strhtml = WebRe.GetResponseStream();
StreamReader stRCmcnHtml = new StreamReader(strhtml, Encoding.GetEncoding("utf-8"));
StreamWriter Sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(filePath), true, Encoding.GetEncoding("utf-8")); ;
Sw.Write("<meta charset='utf-8'/>" + stRCmcnHtml.ReadToEnd());//<meta charset="utf-8"/>百度收录不乱码
Sw.Flush();
Sw.Close();
strhtml.Close();
WebRe.Close();
stRCmcnHtml.Close();
//return true;
}
catch (Exception ex)
{
throw ex;
}
}