0

I am trying to download an image from the open weather org i have the following code.

I am using an Android Device to test my application and gave it the appropriate internet permissions.

I am using the example JSON here

https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22

I no my json decoding is working fine as I see the image name in the result set under the weather object.

public class Weather { public int id { get; set; } public string main { get; set; } public string description { get; set; } public string icon { get; set; } } public async void GetWeather () { result = await restServices.GetWeatherRequest(); lblweather.Text = result.main.temp.ToString(); string url = $"https://openweathermap.org/img/w/{result.weather[0].icon}.png"; imgWeather.Source = new UriImageSource { Uri = new Uri(url), CachingEnabled = true, CacheValidity = new TimeSpan(5, 0, 0, 0) }; } } 

My Main Xaml

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WeatherApp.Views.WeatherMain"> <ContentPage.Content> <StackLayout> <Label Text="Welcome to Xamarin.Forms!" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" /> <Image x:Name="imgWeather"></Image> <Label x:Name="lblweather" ></Label> </StackLayout> </ContentPage.Content> </ContentPage> 

This is the URL that is created by my program which you will see is a valid point.

https://openweathermap.org/img/w/09d.png

3
  • have you verified that url is actually valid and can be loaded in the device/emulator browser? Commented Oct 16, 2019 at 19:30
  • @Jason yes its valid was able to view it in chrome I will show you the url it produced Commented Oct 16, 2019 at 19:35
  • @Jason please see my edit above showing the url of the image produced which is valid Commented Oct 16, 2019 at 19:38

1 Answer 1

1

This appears to have fixed my issue.

As the source of my graphics was from a secure (https) server, therefore, I need to change the following settings. Android Options => Advanced HttpClient implementation = Set to "Managed" option value SSL/TLS implementation = set to "Native TLS 1.2+" option value

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.