C method to download web pages and output them in the console
- 2021-06-29 11:52:53
- OfStack
This article shows an example of how C#downloads a web page and outputs it in the console.Share it for your reference.The implementation is as follows:
using System;
using System.Net;
using System.Text;
using System.IO;
namespace Test {
class GetWebPage {
public static void Main(string[] args) {
for(int i=0;ilt;args.Length;i++) {
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(args[i]);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(stream, Encoding.ASCII);
Console.WriteLine(streamReader.ReadToEnd());
}
Console.Read();
}
}
}
I hope that the description in this paper will be helpful to everyone's C#program design.