HttpResponseMessage not working

I am trying to access a local WebApi. The iOS simulator can access it but the android simulator can not. The android simulator works with the sample data.
I am using Visual Studio Community 2017 on a Mac.

public ChannelList()
{
InitializeComponent();
// Channel.SampleData();

        Channel.Channels.Clear();

        var client = new HttpClient();

         client.BaseAddress = new Uri("http://localhost:5000/api/channels");

          client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

           HttpResponseMessage response = client.GetAsync("").Result;

           response.EnsureSuccessStatusCode();

          string content = response.Content.ReadAsStringAsync().Result;

           var channelsFromService = JsonConvert.DeserializeObject
               <IEnumerable<Channel>>(content);

           foreach (Channel c in channelsFromService
                   .OrderBy(channel => channel.ChannelName))
          {
             Channel.Channels.Add(c);
         }

        BindingContext = Channel.Channels;

Answers

  • kentuckerkentucker USMember ✭✭✭✭✭

    Try replacing localhost with your computer name. The web service is running on your computer not the phone simulator

Sign In or Register to comment.