c# - Http.HttpRequestException Xamarin.forms

标签 c# android xamarin https xamarin.forms

目前我正在尝试模拟我的 Android 应用程序。开发的应用程序使用 xamarin.forms,可在 Android 和 iOS 上运行。

我的问题是使用httpClient 进行restful 请求时。目前我正在使用本地主机。在 iOS 上运行时没有任何问题,但是 Android 返回以下异常: enter image description here

这是导致问题的代码:

var request = new HttpRequestMessage(HttpMethod.Post, sharedURL.baseUrl + "connect/token");
request.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
    ["grant_type"] = "password",
    ["username"] = username,
    ["password"] = password,
    ["scope"] = "offline_access"
});

var response = await client.SendAsync(request, HttpCompletionOption.ResponseContentRead);

我相信这可能与 https 有关,因为我的 Restfull 服务不是使用 https 设置的。但是我无法在 Android 上禁用此功能。有什么线索吗?

最佳答案

我在发布版本上遇到了同样的问题(调试工作正常)。检查我的 droid 项目的“互联网”权限就成功了。

Check internet permission to fix

关于c# - Http.HttpRequestException Xamarin.forms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44177530/

相关文章:

c# - AspNetCore默认授权用户未经过身份验证

android - 具有apk拆分的Firebase应用程序分发无法找到apk

c# - 从 Xamarin Forms 连接到 RESTful 服务的本地调试实例时出现问题

xamarin.android - 如何使用 mvvmcross 将子选项卡添加到选项卡内容

java - com.github.bumptech.glide :glide making app crash

ios - native 链接错误 : 1 duplicate symbol for architecture x86_64

c# - 在 UWP C# 中不使用 MediaComposition 从 SoftwareBitmap 或 Direct3DSurface 创建视频文件

C# 检查 ConsoleKeyInfo.KeyChar 是否为数字

c# - 使用特定 CA 进行 SSL 连接

android - 如何在 AOSP 启动器之前添加我的应用程序