public MovieDetailedInfo GetMovieRestSharp(string location, string ID) { String APIDataString = null; String uri = dataSourceURL + location + "/movie/" + ID; try { var client = new RestClient(uri); var request = new RestRequest(Method.GET); client.Timeout = 60000; //add HTTP Headers request.AddHeader("x-access-token", APItoken); // execute the request IRestResponse response = client.Execute(request); APIDataString = response.Content; // raw content as string MovieDetailedInfo DataModel = JsonConvert.DeserializeObject <MovieDetailedInfo>(APIDataString); return(DataModel); } catch (Exception ex) { MovieDetailedInfo movieInfo = new MovieDetailedInfo { Price = -1 }; return(movieInfo); } }
public MovieDetailedInfo GetMovie(string location, string ID) { String APIDataString = null; String uri = "http://webjetapitest.azurewebsites.net/api/" + location + "/movie/" + ID; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); //request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; request.Headers.Add("x-access-token", "sjd1HfkjU83ksdsm3802k"); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { APIDataString = reader.ReadToEnd(); } MovieDetailedInfo DataModel = JsonConvert.DeserializeObject <MovieDetailedInfo>(APIDataString); return(DataModel); } catch (Exception ex) { MovieDetailedInfo movieInfo = new MovieDetailedInfo(); movieInfo.Price = -1; return(movieInfo); } }