forked from DanWBR/dwsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmlDownload.cs
42 lines (38 loc) · 1.54 KB
/
HtmlDownload.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// ------------------------------------------------------
/// RandomOps - (Pseudo) Random Number Generator For C#
/// Copyright (C) 2003-2010 Magnus Erik Hvass Pedersen.
/// Please see the file license.txt for license details.
/// RandomOps on the internet: http://www.Hvass-Labs.org/
/// ------------------------------------------------------
using System.Net;
using System.IO;
namespace RandomOps
{
/// <summary>
/// Methods for downloading a web-page from the internet.
/// </summary>
static class HtmlDownload
{
/// <summary>
/// Download webpage from given url-address to a StreamReader object.
/// </summary>
/// <param name="url">Internet address of web-page to download.</param>
/// <returns>StreamReader-object with web-page contents.</returns>
public static StreamReader HtmlToStream(string url)
{
WebRequest webRequest = WebRequest.Create(url);
WebResponse webResponse = webRequest.GetResponse();
StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
return streamReader;
}
/// <summary>
/// Download webpage from given url-address to a string.
/// </summary>
/// <param name="url">Internet address of web-page to download.</param>
/// <returns>String with web-page contents.</returns>
public static string HtmlToString(string url)
{
return HtmlToStream(url).ReadToEnd();
}
}
}