日期:2014-05-17 浏览次数:20740 次
//构造web请求,发送请求,获取响应
WebRequest HttpWebRequest = null;
WebResponse HttpWebResponse = null;
HttpWebRequest = WebRequest.Create(url);
HttpWebResponse = HttpWebRequest.GetResponse();
//获得流
sr = new StreamReader(HttpWebResponse.GetResponseStream(), code);
strHtml = sr.ReadToEnd();
//写入文件
try
{
sw = new StreamWriter(fna, false, code);
sw.Write(strHtml);
sw.Flush();
ok = true;
}
catch (Exception ex)
{
HttpContext.Current.Response.Write("<p>写入文件出错:" + ex.Message);
HttpContext.Current.Response.End();
ok = false;
}
finally
{
sw.Close();
}
return ok;
}
?
调用就这样了