Articles → ASP .NET WEB API → Consume Web API Get method using C#

Consume Web API Get method using C#






Create web API




public class TestController: ApiController {
  public List < string > GetTrafficSignalColor() {
    return new List < string > () {
      "Red",
      "Green",
      "Orange"
    };
  }
}



Create C# application




using(var client = new WebClient()) {
  client.Headers["request-type"] = "application/json";
  string result = client.DownloadString("http://localhost:19800/api/Test");
  Console.WriteLine(result);
  Console.ReadLine();
}



Output





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, February 27, 2016

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250