C # Send an Http request,
The WebClient is located in the System. Net namespace. This class allows you to easily create Http requests and obtain the returned content.
I. Usage 1-DownloadData
String uri = "http://hovertree.top/"; WebClient wc = new WebClient (); Console. writeLine ("Sending an http get request to" + uri); byte [] bResponse = wc. downloadData (uri); string strResponse = Encoding. ASCII. getString (bResponse); Console. writeLine ("HTTP response is:"); Console. writeLine (strResponse); // question
Ii. Usage 2-OpenRead
String uri = "http://hovertree.net"; WebClient wc = new WebClient (); Console. writeLine ("Sending an http get request to" + uri); Stream st = wc. openRead (uri); StreamReader sr = new StreamReader (st); string res = sr. readToEnd (); sr. close (); st. close (); Console. writeLine ("HTTP Response is"); Console. writeLine (res); // question
Recommended: http://www.cnblogs.com/roucheng/p/3521864.html