Created
June 19, 2015 23:48
-
-
Save tieorange/97f814b5f6f5fa29a4a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Web; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using RestSharp; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Threading.Tasks; | |
namespace ConsoleApplicationAPI_test | |
{ | |
internal class Program | |
{ | |
//http://api.openweathermap.org/data/2.5/weather?q=London,uk | |
public static String endPoint = "http://api.openweathermap.org/data/2.5/"; | |
private static string weatherQLondonUk = "weather?q=London,uk"; | |
private static void Main(string[] args) | |
{ | |
// var client = new RestClient(endPoint); | |
RunAsync().Wait(); | |
//getWeather(); | |
} | |
private static async Task RunAsync() | |
{ | |
using (var client = new HttpClient()) | |
{ | |
client.BaseAddress = new Uri(endPoint); | |
client.DefaultRequestHeaders.Accept.Clear(); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
// New code: | |
HttpResponseMessage response = await client.GetAsync(weatherQLondonUk); | |
if (response.IsSuccessStatusCode) | |
{ | |
WeatherDAL product = await response.Content.ReadAsAsync<WeatherDAL>(); | |
Console.WriteLine("{0}\t${1}\t{2}", product.main.temp, product.main.humidity, product.main.temp_max); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment