【发布时间】:2019-06-09 13:28:12
【问题描述】:
我的 MainPage 代码隐藏:
private void Button_Clicked(object sender, EventArgs e)
{
Query().Wait();
App.Current.MainPage = new Categories();
}
public async Task Query()
{
restaurantsClient = (App.Current as App).restaurantsClient;
try
{
var restaurantsNames = await restaurantsClient.GetCatalogsAsync(1);
}
catch (Exception ex)
{
var x = 0;
}
}
我也试过这段代码,但没用,出现同样的问题:
async static Task GetRequest(String URL)
{
using (HttpClient client = new HttpClient())
{
// As soon as I try to step over (or even into) this next line, it crashes.
using (HttpResponseMessage response = await client.GetAsync(URL))
{
using (HttpContent content = response.Content)
{
string data = await content.ReadAsStringAsync();
Console.WriteLine(data);
}
}
}
}
C# 中的 Rest-API:
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
当项目到达这条线时,它就会死掉而没有显示任何错误。 如果我在浏览器中这样做,它就可以工作。 API 在我的 PC 本地运行(我使用 Conveyor 公开 API)。
好的,我制作一个视频来更好地了解我在说什么: https://youtu.be/ONKTipPsEXI 正如您在响应行中单击下一步后所看到的,停止执行其余代码。
【问题讨论】:
标签: c# android xamarin.forms httpclient