Wednesday, 14 January 2015

Asp.net HttpClient POST Method call API

string response = null;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BASE_URL);
                var content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair<string, string>("param1", value1),
                        new KeyValuePair<string, string>("param2", value2),
                    });
                var result = client.PostAsync(API_URL, content).Result;
                response = result.Content.ReadAsStringAsync().Result;
              

            }


here BASE_URL is some thing like www.mastermoin.com


and API_URL is looking like /api/helloservice

No comments:

Post a Comment