我创建了一个应用程序,使用Ionic本地HTTP成功地连接到我们的服务器,并在三星Galaxy版本Marshmallow和其他几个还没有使用Android的用户上进行测试。出于某种原因,当我用Android下的设备测试它时,它将不再工作了,而且我收到了CORS策略问题。有没有人遇到过类似的问题?有办法解决这个问题吗?不幸的是,服务器配置中的修改不是一个选项。我也读过一些关于代理的解决方案,但不知道如何实现它们。
版本: cordova-plugin-advanced-http: 2.1.1离子型-本地/http: 5.8.0
发布于 2019-06-28 04:44:11
默认情况下,Android需要HTTPS。这意味着,如果您在应用程序中使用未加密的HTTP请求,则该应用程序在所有较低版本的应用程序中都会运行良好。
若要避免此安全异常,请尝试在应用程序代码中进行以下更改。
在AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>在res/xml中添加名为:network_security_config.xml的文件
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
// Add host of your download URL in below line.
// ie. if url is "https://www.google.com/search?source=...."
// then just add "www.google.com"
<domain includeSubdomains="true">www.google.com</domain>
</domain-config>
</network-security-config>发布于 2020-02-18 12:55:36
要解决这个问题,您应该对config.xml文件进行更改。
您需要更改的第一件事是“小部件”标记,它应该与此类似:
<widget id="com.dynamicsoft.app" version="2.2.2" xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">在此之后,在名称=‘android’的平台中,您应该添加以下代码:
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>之后,您可以运行重新构建应用程序。
https://stackoverflow.com/questions/56799906
复制相似问题