zoukankan      html  css  js  c++  java
  • 【.Net】HttpClient 的使用

     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 及其以上 

  • 相关阅读:
    [Codechef Coders' Legacy 2018 CLSUMG]Sum of Primes
    [HDU4630]No Pain No Game
    [Luogu4329][COCI2006]Bond
    [数论]Gcd/ExGcd欧几里得学习笔记
    [数论]线性基学习笔记
    [Luogu5190][COCI2010]PROGRAM
    IIS7 HTTPS 绑定主机头,嘿嘿,转
    React
    ios
    iOS10 权限配置
  • 原文地址:https://www.cnblogs.com/yanglang/p/7212216.html
Copyright © 2011-2022 走看看