C#生成单页静态页简单实例
程序员文章站
2023-12-16 17:16:10
本文实例讲述了c#生成单页静态页简单实现方法。分享给大家供大家参考。具体方法如下:
复制代码 代码如下:protected void btgroup_serverclic...
本文实例讲述了c#生成单页静态页简单实现方法。分享给大家供大家参考。具体方法如下:
复制代码 代码如下:
protected void btgroup_serverclick(object sender, eventargs e)
{
//产业群首页
string tempgroupdata = gethttpdata("http://www.xxxx.com/test/index.aspx");
using (streamwriter sw = new streamwriter(this.request.physicalapplicationpath + "group\\index.html", false, system.text.encoding.getencoding("utf-8")))
{
sw.write(tempgroupdata);
sw.flush();
}
}
public string gethttpdata(string surl)
{
string srslt = null;
webresponse owebrps = null;
webrequest owebrqst = webrequest.create(surl);
owebrqst.timeout = 50000;
try
{
owebrps = owebrqst.getresponse();
}
finally
{
if (owebrps != null)
{
streamreader ostreamrd = new streamreader(owebrps.getresponsestream(), system.text.encoding.getencoding("utf-8"));
srslt = ostreamrd.readtoend();
ostreamrd.close();
owebrps.close();
}
}
return srslt;
}
{
//产业群首页
string tempgroupdata = gethttpdata("http://www.xxxx.com/test/index.aspx");
using (streamwriter sw = new streamwriter(this.request.physicalapplicationpath + "group\\index.html", false, system.text.encoding.getencoding("utf-8")))
{
sw.write(tempgroupdata);
sw.flush();
}
}
public string gethttpdata(string surl)
{
string srslt = null;
webresponse owebrps = null;
webrequest owebrqst = webrequest.create(surl);
owebrqst.timeout = 50000;
try
{
owebrps = owebrqst.getresponse();
}
finally
{
if (owebrps != null)
{
streamreader ostreamrd = new streamreader(owebrps.getresponsestream(), system.text.encoding.getencoding("utf-8"));
srslt = ostreamrd.readtoend();
ostreamrd.close();
owebrps.close();
}
}
return srslt;
}
希望本文所述对大家的c#程序设计有所帮助。
推荐阅读