我正在处理 xamarin 表单.我在哪里使用 API.当我在 android 5 中运行该应用程序时,它运行良好,但如果我运行的是 7 +,则会出现类似
I am working on xamarin forms. Where I am consuming the API. When I am running the app in android 5 it is working fine but If I am running 7 + it is giving the error like
无法解析主机almsdev.southeastasia.cloudapp.azure":没有与主机名关联的地址.
Unable to resolve host "almsdev.southeastasia.cloudapp.azure": No address associated with hostname.
如何解决这个问题?
以下是代码片段:
public async Task<HttpResponseMessage> Login(string EmailOrMobile) { try { var responseTask = await client.GetAsync(OauthBaseUrl + "OAuthSAAS/MSLogin?UserCredentials=" + EmailOrMobile); return responseTask; } catch (Exception ex) { Crashes.TrackError(ex); return null; } }点击按钮时我正在调用上面的方法
On button click I am calling above method
private async void fn_Submit_Clicked(object sender, EventArgs e) { var response = await _oauthService.Login(txt_credentails.Text.Trim()); }我的基本网址是almsdev.southeastasia.cloudapp.azure:81/api/
我正在使用Http 客户端 = new Http();
I am using Http client = new Http();
推荐答案由于您的目标是 Android 9.0(API 级别 28),默认情况下禁用明文(非 HTTPS)支持.要解决此问题,您可以:使用 HTTPS,或者添加配置以允许 http 流量.
Since you are targeting Android 9.0(API level 28) cleartext(non-HTTPS) support is disabled by default. To overcome this you can: either use HTTPS, or, add configs to allow http traffic.
首先,在您的 Android 项目中,创建一个文件夹:xml 并添加文件 network_security_config
First, in your Android Project, create a folder: xml and add the file network_security_config
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">almsdev.southeastasia.cloudapp.azure</domain> </domain-config> </network-security-config>然后,在您的 Manifest.xml
<application android:label="YourAppName" android:networkSecurityConfig="@xml/network_security_config">您可以在 Xamarin 博客文章
更多推荐
如何解决“无法解析主机"错误?
发布评论