.Net Standard Http請求執行個體

來源:互聯網
上載者:User

標籤:lis   www   檔案   .dll   tor   程式   lin   ada   logs   

一 、.Net Standard http協議封裝

程式集:

System.Net.Http.dll

命名 空間:System.Net.Http

HttpClient :http請求 發送類

FormUrlEncodedContent:Http請求表單參數

HttpResponseMessage:  http請求相應操作

HttpContent:http請求相應內容讀取

 

二、Http Get請求樣本

//使用 HttpClient建立Get請求HttpClient client = new HttpClient();Task<HttpResponseMessage> resp = client.GetAsync("http://www.gongjuji.net");resp.ContinueWith(q =>{    //擷取相應狀態    HttpResponseMessage respMsg = q.Result;    Console.WriteLine(respMsg.StatusCode);    //擷取相應內容    HttpContent respClient = respMsg.Content;    respClient.ReadAsStringAsync().ContinueWith(str =>    {        string result = str.Result;        Console.WriteLine(result);    });});

三、Http  Post請求樣本

//使用HttpClient 建立Post請求HttpClient client = new HttpClient();//指定提交表單資料List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>();paramList.Add(new KeyValuePair<string, string>("Content", "e"));FormUrlEncodedContent data = new FormUrlEncodedContent(paramList);client.PostAsync("http://md5.gongjuji.net/common/md5encrypt", data)    .ContinueWith(q =>    {        HttpResponseMessage respMsg = q.Result;        //讀取請求結果        respMsg.Content.ReadAsStringAsync().ContinueWith(str =>        {            string result = str.Result;            Console.WriteLine(result);        });    });

 

更多:

.Net Standard簡介

.Net Core設定檔讀取整理

EF Core 1.0 和 SQLServer 2008 分頁的問題

.Net Standard Http請求執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.