作者:forsoz_627 | 来源:互联网 | 2022-11-23 11:46
我正在尝试连接到这些地方之一并获取JSON数据:-
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应用访问它们时,出现以下错误:
NetworkSecurityConfig: No Network Security Config specified, using platform default
Error response code: 400
我已将此添加到manifest.xml:-
我还将此添加到manifest.xml:
android:networkSecurityCOnfig="@xml/network_security_config"
并创建了res / xml / network_security_config.xml,其中包含:-
content.guardianapis.com>
将错误更改为:
D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
Error response code: 400
我知道它不见了:
但我不知道证书在哪里或在什么地方,是否需要它。
不太确定发生了什么,将不胜感激。
另外:-我可以很好地连接并从此URL获取JSON:-
https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&eventtype=earthquake&orderby=time&minmag=6&limit=10
我所得到的是:
No Network Security Config specified, using platform default
购买不是错误400,而是获得200。因此,这让我觉得有些奇怪的事情正在发生,但不确定在哪里。
1> Quick learne..:
试试这些解决方案
解决方案1)
将以下属性添加到中的标记中AndroidManifest.xml
:
android:usesCleartextTraffic="true"
解决方案2)
android:networkSecurityCOnfig="@xml/network_security_config"
将标签添加到中app/src/main/AndroidManifest.xml
:
带有一个对应network_security_config.xml
的app/src/main/res/xml/
:
请参阅此答案以获取更多信息:
下载无法在Android Pie 9.0(Xiaomi mi A2)中使用的Manger