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
|
using System; using System.IO; using System.Net; using System.Collections.Generic; using System.Linq; using System.Text; namespace webclient { class Program { static void Main( string [] args) { WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; // 拿到一个请求 HttpWebResponse response = (HttpWebResponse)request.GetResponse (); Console.WriteLine (response.StatusDescription); Stream dataStream = response.GetResponseStream (); StreamReader reader = new StreamReader (dataStream); string responseFromServer = reader.ReadToEnd (); Console.WriteLine (responseFromServer); reader.Close (); dataStream.Close (); response.Close (); } } } |