📄 singlepage.cs
字号:
using System;
using System.Text;
using System.IO;
using System.Collections;
using System.Net;
namespace SinglePage
{
/// <summary>
/// Summary description for SinglePage.
/// </summary>
public class SinglePage
{
/// <summary>
/// Download HTML code of given URL.
/// </summary>
/// <param name="URL">URL</param>
/// <param name="HTML">HTML code</param>
/// <returns>true if successfully download, false if Unable to process request at this time.</returns>
public static bool Download(string URL, ref string HTML)
{
Stream strmPage = null;
StreamReader srPage = null;
try
{
HttpWebRequest wrqPage = (HttpWebRequest)WebRequest.Create(URL);
wrqPage.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
WebResponse wrpPage = wrqPage.GetResponse();
strmPage = wrpPage.GetResponseStream();
srPage = new StreamReader(strmPage);
HTML = srPage.ReadToEnd();
strmPage.Close();
return true;
}
catch (Exception ex)
{
SinglePage.LogAppend("Download ["+URL+"] Error:\n"+ex.Message);
if (strmPage != null)
{
strmPage.Close();
}
return false;
}
}
/// <summary>
/// Append some content [log] to the log file.
/// If the file is not exist, it will be created automatically by this function.
/// </summary>
/// <param name="log">Content string to be appended.</param>
public static void LogAppend(String log)
{
FileInfo file = new FileInfo("log.ini");
if(!file.Exists)
{
FileStream fs = file.Create();
fs.Close();
}
StreamWriter w = new StreamWriter(file.FullName,true);
w.WriteLine(log);
w.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -