Friday, March 13, 2015

Call ASP.Net Web Api using WebRequest & WebResponse

I was trying to find a way to call web api from my console application. I came across with .net abstract class WebRequest (link) which can call web api. It has one derived class HttpWebRequest (link) which has more helpful properties to call web api. So, I will use this here. We use WebResponse class (link) to receive response.

Sample Code:























Note: One can use this code to access any URL. I have used web api as example here.