如何解决“无法解析主机"错误?

编程入门 行业动态 更新时间:2024-10-26 08:23:04
本文介绍了如何解决“无法解析主机"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在处理 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 博客文章

更多推荐

如何解决“无法解析主机"错误?

本文发布于:2023-06-05 01:12:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/508804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何解决   错误   主机   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!