static void Main(string[] args) { var weatherParameters = new GET_Weather() { appId = "3901dadab60ac7e843958b159be48e34", q = "New Delhi", mode = "xml" }; string response = Rest.sendRequest(Rest.REQUEST.GET, "https://api.openweathermap.org/data/2.5/weather", weatherParameters); var jsonWeatherModel = J_WeatherModel.Deserialize(response); var xmlWeatherModel = X_WeatherModel.Deserialize(response); //Console.WriteLine(jsonWeatherModel.coord.lat); //Console.WriteLine(xmlWeatherModel.City.Id); }
public static string sendRequest(REQUEST request, string url, GET_Weather parameters) { string responseString = string.Empty; if (request == REQUEST.GET) { var client = (HttpWebRequest)WebRequest.Create(url + parameters.getQueryString()); client.Method = request.ToString(); client.ContentLength = 0; var response = (HttpWebResponse)client.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { return(String.Format("Request Failed, HTTP Status Code : {0}", response.StatusCode)); } var responseStream = response.GetResponseStream(); if (responseStream != null) { var streamReader = new StreamReader(responseStream); responseString = streamReader.ReadToEnd(); } } return(responseString); }