public async Task <string> GetTodayWallpaperUrlAsync() { string urlResult = string.Empty; try { BingModel model = new BingModel(); var requestUrl = new Uri(BASE_URL + "HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"); HttpClient client = new HttpClient(); var response = await client.GetAsync(requestUrl); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); model = JsonConvert.DeserializeObject <BingModel>(content); } if (model.Images != null) { urlResult = BASE_URL + model.Images.FirstOrDefault().Url; } } catch (Exception ex) { urlResult = ex.Message; } return(urlResult); }
public Image GetTodayWallpaperUrl() { BingModel model = new BingModel(); try { var requestUrl = new Uri(BASE_URL + "HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"); HttpClient client = new HttpClient(); var response = client.GetAsync(requestUrl); if (response.Result.IsSuccessStatusCode) { var content = response.Result.Content.ReadAsStringAsync(); model = JsonConvert.DeserializeObject <BingModel>(content.Result); } if (model.Images != null) { model.Images.FirstOrDefault().Url = BASE_URL + model.Images.FirstOrDefault().Url; } } catch (Exception) { } return(model.Images.FirstOrDefault()); }
public static string ToJson(this BingModel self) => JsonConvert.SerializeObject(self, Converter.Settings);