Forum Xamarin.Forms

Why I am getting a http request exception ?

DyaryDyary Member ✭✭

Hi . I am trying to execute this simple code but it fails and i getSystem.Net.Http.HttpRequestException: An error occurred while sending the request ?

The code simply declares an HttpCLient and then I use the GetStringMethod. the same code used to work. I don't know why it doesn't now.
I searched google and stackoverflow and couldn't get the answer.

Here is my .cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using FetchActor.Models;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using System.Collections;

namespace FetchActor
    public partial class MainPage : ContentPage

        HttpClient connection = new HttpClient();
        MovieService movieService = new MovieService();

        public MainPage()


        private async void searchBarByActor_SearchButtonPressed(object sender, EventArgs e)

            var _connection = await connection.GetStringAsync("");


the code never goes past GetStringAsync and i get the error.
any ideas on what could this be please ?


  • DyaryDyary Member ✭✭

    the ANSWER : It seems the emulator wasn't get data from the connection. I turned the Wifi on and off and restarted the computer and the project. it still didn't work. it was showing connected but no internet.

    the solution was turning off mobile data in the emulator so that it could be connected only with wifi.

Sign In or Register to comment.