Post方法在Xamarin Forms iOS中永远不会返回

本文关键字:永远 返回 iOS 方法 Xamarin Forms Post | 更新日期: 2023-09-27 17:54:25

我正在使用以下代码片段:

public async Task<LoginUser[]> GetUserAsync()
{
    var client = new System.Net.Http.HttpClient();
    client.BaseAddress = 
        new Uri("http://developer-platform.com/dutyfreebuzz/web_services/Login");
    StringContent str = new StringContent("username=admin&password=12345", Encoding.UTF8, "application/x-www-form-urlencoded");
    var response = await client.PostAsync(new Uri("http://developer-platform.com/dutyfreebuzz/web_services/Login/loginJSON"), str);
    var loginJson = await response.Content.ReadAsStringAsync();
    Rootobject rootobject = new Rootobject();
    if (loginJson != "")
    {
        //rootobject = JsonConvert.DeserializeObject<Rootobject>(loginJson);
    }
    //return rootobject.loginusers;
}

我已经为这个函数设置了断点。在执行期间,调试器不会移动到PostAsync调用,并且它正在移出函数。

Post方法在Xamarin Forms iOS中永远不会返回

这个答案是Cheesebaron和OP的评论摘要,因为解决方案在评论中提供

如果在iOS上启用了链接器,则在可移植类库中的async/await代码中设置断点存在当前已知的问题。

41836:对于iOS应用程序,PCL项目中异步方法中的断点如果启用了链接器,则不会命中。部分临时解决方法:将"项目属性">"iOS构建">"链接器行为"设置为"不链接"。(不幸的是,对于设备构建,此解决方法确实会创建更大的.app捆绑包,可以延长部署时间。(

作为变通办法,在WriteLine():中设置断点

System.Diagnostics.Debug.WriteLine(response);