I am developing an asp.net mvc web application in which I need to call OMDB api (an api to get Imdb information of a movie). I need to send a simple GET request to the api and get the response(movie details), deserialize the response into an object and pass it to the view. Is this possible without using a reference to an external library? Can anybody give me an example on how to do it inside a controller action.
1 Answer
You can use the WebRequest class
using System.Net;
string url = "https://www.service.com?param=movieName";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
Reference:
1 Comment
Deepal
thanks for the answer and it worked well! I used
StreamReader class to read the responseStream.