Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms Images not loading from remote URL

I have a demo xamarin forms project that simply displays an image with its image source set to a remote URL. But the problem is it works for some URL and does not for others. I have picked up random image links from google image search and compiled a list of the working / non-working ones. Any insight on this strange behavior is hugely appreciated.

Thanks in Advance!

Working URLs

  • https://i.ytimg.com/vi/JTxPzXQ1Sso/maxresdefault.jpg

  • https://media-cdn.tripadvisor.com/media/photo-s/09/97/8c/27/castle-rock-trading-post.jpg

  • https://www.xamarin.com/content/images/pages/forms/example-app.png

Non-Working URLs

  • https://www.seminolehardrockhollywood.com/files/1637/Utilities-EventsCalendar-1250x450.jpg

  • http://melangesimsr.com.103-21-58-169.sdin-pp-wb3.webhostbox.net/Assets/UplaodedFiles/20171122090840812.png

  • https://www.chicagotraveler.com/sites/default/files/concerts-chicago-big-1.jpg

XAML file

<?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:local="clr-namespace:XamarinImageTest"
             x:Class="XamarinImageTest.MainPage"
             BackgroundColor="#000000">

    <ContentPage.Content>
        <Image Source="https://i.ytimg.com/vi/JTxPzXQ1Sso/maxresdefault.jpg" 
               VerticalOptions="Fill"
               HorizontalOptions="Fill"></Image>
    </ContentPage.Content>
</ContentPage>
like image 433
Sreejith Krishnadas Avatar asked Nov 29 '17 10:11

Sreejith Krishnadas


1 Answers

Use native http client handlers + TLS2.0 for your app (can be set in project settings):

  • https://developer.xamarin.com/guides/android/application_fundamentals/http-stack/
  • https://developer.xamarin.com/guides/cross-platform/macios/http-stack/

For iOS also enable http downloads:

  • How do I load an HTTP URL with App Transport Security enabled in iOS 9?
like image 100
Daniel Luberda Avatar answered Sep 20 '22 01:09

Daniel Luberda