为什么我收到http请求异常? [英] Why I am getting a http request exception ?

查看:247
本文介绍了为什么我收到http请求异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我试图执行这个简单的代码,但它失败了,我得到

Quote:

System.Net.Http.HttpRequestException:发送时发生错误请求?





这是我的.cs文件



引用:

使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Net.Http;

使用System.Text;

使用System.Threading.Tasks;

使用Xamarin.Forms;

使用FetchActor.Models;

使用Newtonsoft.Json;

使用System.Collections.ObjectModel;

使用System.Collections;



名称空间FetchActor

{

公共分部类MainPage:ContentPage

{









HttpClient连接= new HttpClient();

MovieService movieService = new MovieService();









public MainPage( )

{

InitializeComponent();



}









private async void searchBarByActor_SearchButtonPressed(object sender,EventArgs e)

{< br $>






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





}

}







代码永远不会超过GetStringAsync和i得到错误。

关于什么可以满足的任何想法?



我尝试了什么:



代码只是声明一个HttpCLient然后我使用GetStringMethod。用于工作的相同代码。我不知道为什么现在没有。



我搜索了谷歌和stackoverflow,但无法得到答案。



感谢任何帮助。

谢谢。

解决方案

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



解决方案是关闭模拟器中的移动数据,以便它只能与wifi连接。


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.

解决方案

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.


这篇关于为什么我收到http请求异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆