Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi . I am trying to execute this simple code but it fails and i get
Quote:
System.Net.Http.HttpRequestException: An error occurred while sending the request ?
.

Here is my .cs file

Quote:
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()
{
InitializeComponent();

}




private async void searchBarByActor_SearchButtonPressed(object sender, EventArgs e)
{



var _connection = await connection.GetStringAsync("https://api.themoviedb.org/3/search/keyword?api_key=ab3da1af35c55cc8b3780fbc9a2bf259&query=Charlize%20Theron&page=1");


}
}



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

What I have tried:

The code simply declare 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.

Any help is appreciated.
Thanks.
Posted
Updated 26-Aug-18 11:21am

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900