Webapi GET request Fromuri List parameter Pass

Source: Internet
Author: User

Today when you make a project call a third-party WEBAPI, find the GET request unexpectedly using the Fromuri list parameter, Khan ...

Here is a simple way to record the request for a parameter (but it is not recommended to use the Get Fromuri list parameter to define the function of Webapi):

1HttpClient hclient =NewHttpClient (NewMyhttpclienhanlder ());2 3             stringURL ="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 9list<Long> PIds =Newlist<Long>();TenPids.add (2322); OnePids.add (1824); A             //list<keyvaluepair<string, string>> paramlist = new list<keyvaluepair<string, string>> () ; -             //Paramlist.add (New keyvaluepair<string, string> ("PkIds", Newtonsoft.Json.JsonConvert.SerializeObject ( (PIDS) )); -  the             stringParasformat ="pkids[{0}]={1}&"; -StringBuilder paras =NewStringBuilder (); -              for(vari =0; i < Pids.count; i++) -             { + paras. AppendFormat (Parasformat, I, pids[i]); -             } +  AURL ="http://api.test.com/api/pk/list?"+ paras. Remove (paras. ToString (). Length-1,1). ToString (); at  -             //var ret = hclient.postasync (URL, new Formurlencodedcontent (paramlist)); -             varRET =hclient.getasync (URL); -             varSS =ret. Result.Content.ReadAsStringAsync (). Result; - Console.WriteLine (ss); -  inHclient.dispose ();

Webapi GET request Fromuri List parameter Pass

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.