如何解决“无法解析主机"错误? [英] How to resolve "Unable to resolve host" error?

查看:72
本文介绍了如何解决“无法解析主机"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 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.com":没有与主机名关联的地址.

Unable to resolve host "almsdev.southeastasia.cloudapp.azure.com": 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()); 
 }

我的基本网址是
http://almsdev.southeastasia.cloudapp.azure.com: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.com</domain>
  </domain-config>
</network-security-config>

然后,在您的 Manifest.xml

   <application android:label="YourAppName" android:networkSecurityConfig="@xml/network_security_config">

您可以在 Xamarin 博客文章

这篇关于如何解决“无法解析主机"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆