大家好,又见面了,我是全栈君
WebClient位于System.Net命名空间下,通过这个类可以方便的创建Http请求并获取返回内容。
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);
// 何问起
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);
// 何问起
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/120316.html原文链接:https://javaforall.cn