Webapi get request FromUri list parameter transfer, webapifromuri

Source: Internet
Author: User

Webapi get request FromUri list parameter transfer, webapifromuri

When a project calls a third-party webapi today, it finds that the get request uses the FromUri list parameter, Khan...

Here, we will briefly record the request parameter passing method (but we do not recommend that you use the get FromUri list parameter to define the webapi function ):

 1        HttpClient hClient = new HttpClient(new MyHttpClienHanlder()); 2  3             string url = "http://api.test.com/api/pk/index?pkId=2322"; 4             //var ret = hClient.GetAsync(url); 5             //var ss = ret.Result.Content.ReadAsStringAsync().Result; 6             //Console.WriteLine(ss); 7             //Console.WriteLine("\r\n\r\n\r\n****************************************************************\r\n\r\n\r\n"); 8  9             List<long> pIds = new List<long>();10             pIds.Add(2322);11             pIds.Add(1824);12             //List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();13             //paramList.Add(new KeyValuePair<string, string>("pkIds", Newtonsoft.Json.JsonConvert.SerializeObject(pIds)));14 15             string parasFormat = "pkIds[{0}]={1}&";16             StringBuilder paras = new StringBuilder();17             for (var i = 0; i < pIds.Count; i++)18             {19                 paras.AppendFormat(parasFormat, i, pIds[i]);20             }21 22             url = "http://api.test.com/api/pk/list?" + paras.Remove(paras.ToString().Length - 1, 1).ToString();23 24             //var ret = hClient.PostAsync(url, new FormUrlEncodedContent(paramList));25             var ret = hClient.GetAsync(url);26             var ss = ret.Result.Content.ReadAsStringAsync().Result;27             Console.WriteLine(ss);28 29             hClient.Dispose();

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.