我正在尝试找出我的 C# Xamarin Android 代码中的错误。这个应用程序应该做的很简单 - 连接到 REST API,将内容下载为字符串以供进一步分析。起初我的错误是不包括异步任务并使用 voids 代替,但是当我更改它们时,代码似乎卡在检索数据的点上。
String content;
private void OnClick1(object sender, EventArgs e)
{
output.Text = "";
GetJSONTextFromWeb("https://ameobea.me/osutrack/api/get_changes.php?user=XXXXXX&mode=0", "XXXXXX", "0");
while (content==null)
{
DoNothing();
}
output.Text = content;
}
private async Task GetJSONTextFromWeb(String address, String user, String modeID)
{
URL url = new URL(address);
URLConnection conn = url.OpenConnection();
//conn.AddRequestProperty("user", user); those lines are
//conn.AddRequestProperty("mode", modeID); removed for investigation.
//conn.Connect(); //this one caused the same issue.
content = (String)conn.Content; //Here the code seems to freeze without any warning.
}
private void DoNothing()
{
//literally. Made to await for the result.
}
有谁知道可能的原因?
相关分类