首页 > 解决方案 > 使用 android 模拟器时流意外结束

问题描述

我有一个通过 android 模拟器向我的本地主机发送发布请求的应用程序。当我使用我的应用程序的 UWP 端时,发布请求工作正常,但是当我切换到 android 时,我得到了意外的流异常结束。是一个截图

这是我必须发送包含所有必需信息的发布请求的当前代码。我花了几个小时浏览多个帖子,但无济于事。

string URL = "http://192.168.1.178:44310/";
    public async Task<bool> RegisterAsync(string usrname, string firstName, string secondName, string email, string password, string confirmPassword)
    
    {
        bool Response = false;

        var client = new HttpClient();

        var model = new RegisterBindingModel
        {
            UsrName = usrname,
            FirstName = firstName,
            SecondName = secondName,
            Email = email,
            Password = password,
            ConfirmPassword = confirmPassword


        };
        
        var json = JsonConvert.SerializeObject(model);

        HttpContent content = new StringContent(json);
        
        content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");

        var response = client.PostAsync( URL +"api/Account/Register", content);
        var mystring = response.GetAwaiter().GetResult();
        if(response.Result.IsSuccessStatusCode)
        {
            Response = true;
        }
        
        return Response;
        
    }

我应该提到的另一件事是,当我从 android 切换到 UWP 时,我必须将 URL 切换到

string URL = "http://localhost:44310/";

而不是这个

string URL = "http://192.168.1.178:44310/";

我使用上面代码的原因是因为我使用的是模拟器,我不确定我在这里放其他东西是否会修复它。非常感谢!

标签: asp.netxamarin.formsvisual-studio-2019

解决方案


推荐阅读