-1

I have my own Web API application in which i want to call the another api which is on server. How can i do that ?

var result = url(http://54.193.102.251/CBR/api/User?EmpID=1&ClientID=4&Status=true);
// Something like this.
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
sbm6070
  • 45
  • 2
  • 7
  • 2
    Possible duplicate of [How do I make calls to a REST api using c#?](https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c) – CodeCaster Jun 15 '17 at 17:30

1 Answers1

2

You can use HttpClient. Here is a sample of async method which calls your API:

var client = new HttpClient();
client.BaseAddress = new Uri("http://54.193.102.251/CBR/api");
// here you can add additional information like authorization or accept headers
client.DefaultRequestHeaders
   .Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

// you can chose which http method to use
var response = await client.GetAsync("User?EmpID=1&ClientID=4&Status=true");
if (!response.IsSuccessStatusCode)
    return; // process error response here

var json = await response.Content.ReadAsStringAsync(); // assume your API supports json
// deserialize json here
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459