[C#] 纯文本查看 复制代码
#region 简单GET方式请求 +GetUrlHtml(string url, Encoding readCoding, int timeout = 30000, string userAgent = "", CookieCollection cookies = null)
/// <summary>
/// 简单GET方式请求 +GetUrlHtml(string url, Encoding readCoding, int timeout = 30000, string userAgent = "", CookieCollection cookies = null)
/// </summary>
/// <param name="url"></param>
/// <param name="readCoding"></param>
/// <param name="timeout"></param>
/// <param name="userAgent"></param>
/// <param name="cookies"></param>
/// <returns></returns>
public static string GetUrlHtml(string url, Encoding readCoding, int timeout = 30000, string userAgent = "", CookieCollection cookies = null)
{
string content = "";
HttpWebResponse myResponse;
try
{
myResponse = CreateGetHttpResponse(url, timeout, userAgent, cookies);
}
catch (WebException ex)
{
myResponse = (HttpWebResponse)ex.Response;
}
if (myResponse != null)
{
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), readCoding);
content = reader.ReadToEnd();
}
return content;
}
#endregion
不能直接用IO吧,这是我写的下载网页的。。 最后的 StreamReader 你简单改一下,存成别的类型也行。
|