不允许将Android明文HTTP传输到x.x.x.x

问题描述 投票:0回答:1

我试图将图像发送到我的服务器。在我的虚拟设备上,一切正常,但是当我尝试在手机上安装应用程序时出现此错误:java.io.IOException:不允许x.x.x.x的明文HTTP通信。我的手机android版本:9 PKQ1我尝试在此Tuto https://medium.com/@imstudio/android-8-cleartext-http-traffic-not-permitted-73c1c9e3b803之后解决此问题但两种解决方案后的结果相同。我也尝试过这个Android 8: Cleartext HTTP traffic not permitted谢谢您的帮助。

android permissions avd
1个回答
0
投票

它无法在您的移动设备上运行,因为:

您的移动设备支持android版本9(pie)。根据Android版本,由于Google设置的安全原因,您无法通过HTTP请求将请求发送到互联网。您只需要HTTPS。

解决方案:

  1. 使用您网站的安全版本,即https://www.your_site_name
  2. 将您的HTTP网址列入白名单,以便操作系统可以理解这是我不应该阻止的HTTP请求,并将允许您通过HTTP连接。

将饼图的HTTP请求列入白名单的代码:

创建xml资源文件:network_security_configuration.xml

<?xml version="1.0" encoding="utf-8"?> 
<network-security-config> 
    <domain-config cleartextTrafficPermitted="true"> 
        <domain includeSubdomains="true">google.com(your_domain)</domain> 
    </domain-config> 
</network-security-config> 

在Manifest.xml中:

 <application
        //add this below lines under your application tag.
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_configuration">
© www.soinside.com 2019 - 2024. All rights reserved.