Exception 为什么在Xamarin表单中出现http请求异常

Exception 为什么在Xamarin表单中出现http请求异常,exception,xamarin.forms,httprequest,Exception,Xamarin.forms,Httprequest,我试图执行这个简单的代码,但失败了,我得到System.Net.Http.HttpRequestException:发送请求时出错 代码只是声明一个HttpCLient,然后我使用GetStringMethod。与以前的代码相同。我不知道为什么现在没有。 我搜索了谷歌和stackoverflow,却找不到答案 这是我的.cs文件 using System; using System.Collections.Generic; using System.Linq; using System.Net.

我试图执行这个简单的代码,但失败了,我得到System.Net.Http.HttpRequestException:发送请求时出错

代码只是声明一个HttpCLient,然后我使用GetStringMethod。与以前的代码相同。我不知道为什么现在没有。 我搜索了谷歌和stackoverflow,却找不到答案

这是我的.cs文件

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");
        }

    }
}
代码从未经过GetStringAsync,我得到了错误。
有什么想法吗?

似乎模拟器没有从连接中获取数据。我打开和关闭Wifi,重新启动计算机和项目。它仍然不起作用。它显示连接但没有互联网

解决方案是关闭模拟器中的移动数据,使其只能通过wifi连接