NetworkSecurityConfig:未指定网络安全配置,使用平台默认值 [英] NetworkSecurityConfig: No Network Security Config specified, using platform default

查看:8392
本文介绍了NetworkSecurityConfig:未指定网络安全配置,使用平台默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到这些地方之一并获取JSON数据:-

I'm trying to connect to either of these places and get the JSON data:-

https://content.guardianapis.com/search?q=debate&tag=politics/politics&from-date=2014-01-01&api-key=test
https://content.guardianapis.com/search?q=debates&api-key=test
https://content.guardianapis.com/search?api-key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx

我可以通过浏览器访问全部三个,但是当我尝试通过Android应用访问它们时,出现以下错误:-

All three I can get to via the browser, but when I try to access them via an android app I get the following errors:-

NetworkSecurityConfig: No Network Security Config specified, using platform default
Error response code: 400

我已将其添加到manifest.xml:-

I've added this to manifest.xml:-

<uses-permission android:name="android.permission.INTERNET"/>

我还将其添加到manifest.xml:-

I also added this to the manifest.xml:-

android:networkSecurityConfig="@xml/network_security_config"

并创建了res/xml/network_security_config.xml,其中包含:-

And created res/xml/network_security_config.xml, which contains:-

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">content.guardianapis.com</domain>>
    </domain-config>

将错误更改为:-

D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
Error response code: 400

我知道它不见了:-

<trust-anchors>
    <certificates src="@raw/my_ca"/>
</trust-anchors>

但是我不知道证书在哪里,在什么地方或者是否需要它.

but I have no idea where or what the certificate would be or if it's needed.

不太确定发生了什么,将不胜感激.

Not really sure what is going on, any help would be appreciated.

另外:- 我可以很好地连接并从以下URL获取JSON:-

IN ADDITION:- I am able to connect fine and get the JSON from this URL:-

https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&eventtype=earthquake&orderby=time&minmag=6&limit=10

我所得到的就是这个:-

All I get is this:-

No Network Security Config specified, using platform default

不购买错误400,而是购买200.因此,这让我觉得有些奇怪的事情正在发生,但不确定在哪里.

Buy not error 400 and gets through with a 200 instead. So it makes me think there is something weird going on, but not sure where.

推荐答案

尝试这些解决方案

解决方案1 ​​)

AndroidManifest.xml中的<application标记中添加以下属性:

Add the following attribute to the <application tag in AndroidManifest.xml:

android:usesCleartextTraffic="true"

解决方案2 )

app/src/main/AndroidManifest.xml中的<application标记中添加android:networkSecurityConfig="@xml/network_security_config":

<application
        android:name=".ApplicationClass"
        android:allowBackup="true"
        android:hardwareAccelerated="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

app/src/main/res/xml/中带有相应的network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

有关更多信息,请参考此答案: 下载管理器在Android Pie 9.0(Xiaomi mi A2)中无法使用

Refer this answer for more info: Download Manger not working in Android Pie 9.0 (Xiaomi mi A2)

这篇关于NetworkSecurityConfig:未指定网络安全配置,使用平台默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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