1 class Program 2 { 3 public static HttpClient Client; 4 static HttpResponseMessage response; 5 6 static void Main(string[] args) 7 { 8 9 10 var httpClient = new HttpClient(); 11 string url = "http://127.0.0.1/Manager/Login.aspx"; 12 List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>(); 13 paramList.Add(new KeyValuePair<string, string>("Username", "123")); 14 paramList.Add(new KeyValuePair<string, string>("Password", "456")); 15 response = httpClient.PostAsync(new Uri(url), new FormUrlEncodedContent(paramList)).Result; 16 string result = response.Content.ReadAsStringAsync().Result; 17 18 19 paramList = new List<KeyValuePair<string, string>>(); 20 paramList.Add(new KeyValuePair<string, string>("PageIndex", "0")); 21 paramList.Add(new KeyValuePair<string, string>("PageSize", "10")); 22 23 url = "http://127.0.0.1/News/NewsList.aspx"; 24 response = httpClient.PostAsync(new Uri(url), new FormUrlEncodedContent(paramList)).Result; 25 result = response.Content.ReadAsStringAsync().Result; 26 Console.WriteLine(result); 27 Console.Read(); 28 29 30 31 32 } 33 34 }
.net framework 4.5 及其以上