cordova-HTTP:最简单的GET请求不起作用

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

[我正在尝试使用cordova插件“ cordova-HTTP”将GET请求从我的Android仿真器发送到运行该仿真器的笔记本电脑:

cordovaHTTP.get(
            "http://10.0.2.2:80/",
            {},
            {},
            function(response) {
                console.log('success called');
            },
            function(error_response) {console.log('error called'); console.log(error_response.status);}
        );

错误回调被调用,状态代码为500(=内部服务器错误)。但是在我的笔记本电脑上,我可以通过tcpdump看到甚至没有收到任何软件包。为什么这个非常简单的GET请求无法正常工作?

[当我在模拟器上使用Google Chrome浏览器并导航到“ http://10.0.2.2:80/”时,一切正常,我看到了安装在笔记本电脑上的Apache2 Web服务器的虚拟页面。

cordova http android-emulator cordova-plugins http-get
1个回答
0
投票

由于API级别28,默认情况下不允许发送简单的GET请求,因为不允许明文通信。因此,我将以下内容添加到了cordova项目的config.xml中(在<platform name="android">标记内):

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application"> 
<application android:usesCleartextTraffic="true" /> 
</edit-config>
© www.soinside.com 2019 - 2024. All rights reserved.