星空网 > 软件开发 > ASP.net

用asp.net c# HttpWebRequest获取网页源代码

public string GetPage(string url)
{

HttpWebRequest request = null;

HttpWebResponse response = null;

StreamReader reader = null;

try
{

request = (HttpWebRequest)WebRequest.Create(url);

request.Timeout = 20000;

request.AllowAutoRedirect = false;

response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK && response.ContentLength < 1024 * 1024)
{

reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);

string html = reader.ReadToEnd();

return html;

}

}

catch
{

}

finally
{

if (response != null)
{

response.Close();

response = null;

}

if (reader != null)

reader.Close();

if (request != null)

request = null;

}

return string.Empty;
}




原标题:用asp.net c# HttpWebRequest获取网页源代码

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

电商自建站引流:https://www.goluckyvip.com/tag/30435.html
电商做跨境:https://www.goluckyvip.com/tag/30436.html
电诉宝:https://www.goluckyvip.com/tag/30437.html
电索汇条款:https://www.goluckyvip.com/tag/30438.html
电影推广营销方案:https://www.goluckyvip.com/tag/30439.html
旺季遇上疫情:https://www.goluckyvip.com/tag/3044.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
南美旅游报价(探索南美洲的旅行费用):https://www.vstour.cn/a/411234.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流