Android设备与本地API服务器进行通信 [英] Android device communicate with local API server
问题描述
我想知道如何获得被模拟外部设备与本地API服务器在我的机器上运行的沟通我的Android应用。
I would like to know how to get my Android app being simulated on an external device to communicate with a local API server running on my machine.
该应用程序是使用科尔多瓦和正在使用USB连接Android设备上运行。我在本地运行一个API服务器。
The app is using cordova and being run on an Android device using USB connection. I am running an API server locally.
使用我的机器的IP地址,我试图通过HTTP交谈API服务器应用程序中调用。但我得到的调试404错误。
Using my machine's IP address, I am trying to talk to the API server via HTTP calls within the app. But I get 404 errors in the debugger.
POST http://myIP:8083/api/login 404 (Not Found)
API服务器正在运行和访问。我已经通过设备的Web浏览器访问它证实了它。我的直觉是,我要加入白名单的地方我的IP。但我不知道。有什么建议?
The API server is running and accessible. I have confirmed it by accessing it from the device's web browser. My hunch is that I have to whitelist my IP somewhere. But I am not sure. Any suggestions?
使用科尔多瓦5.3.3。对LG电子的Nexus 5的测试4.4.4的Android(API 19)。
Using Cordova 5.3.3. Testing on LGE Nexus 5 Android 4.4.4 (API 19).
推荐答案
通过解决的https:/ /github.com/apache/cordova-plugin-whitelist 插件,并添加< META HTTP-EQUIV =内容安全性政策...>
在<
index.html的
文件
Resolved by using https://github.com/apache/cordova-plugin-whitelist plugin and adding <meta http-equiv="Content-Security-Policy" ...>
in <head>
of index.html
file.
有关更多信息,请参阅 https://github.com/apache /科尔多瓦 - 插件白名单#内容安全政策。
For more info, read https://github.com/apache/cordova-plugin-whitelist#content-security-policy.
这篇关于Android设备与本地API服务器进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!