asp.net - 使用 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/";
我使用上面代码的原因是因为我使用的是模拟器,我不确定我在这里放其他东西是否会修复它。非常感谢!
解决方案
推荐阅读
- swift - 如何用 PHPickerViewController 中的图像替换 livePhoto?
- python-3.x - Python pre-order to postfix notation reverse Polish notation
- python - 如何使用 BeautifulSoup 获取多个 div 下的 div 元素?
- c# - 从包含数组的对象列表中返回不同的列表
- javascript - 带有 Laravel 8 的 SurveyJs 没有 Larvel-surveyjs 包
- c++ - 如何获取 char 数组 char* 的长度
- next.js - Nextjs Auth0 在 getServerSideProps 中获取数据
- lambda-calculus - 减少这个 lambda 表达式
- javascript - 为什么我的搜索栏功能不正常
- swift - 向 Xcode 13+ 添加自定义字体