[英]Ionic 1 external HTTP request
I am trying to consume HTTP services from an external location but only get ERR_CONNECTION_TIMED_OUT because the request never gets to the server. 我正在尝试从外部位置使用HTTP服务,但仅获得ERR_CONNECTION_TIMED_OUT,因为请求从未到达服务器。
The app have been built with ionic 1
and angularjs
, using angular-resource
to consume services 该应用程序是使用ionic 1
和angularjs
,使用angular-resource
来使用服务
After reading several SO questions I end up setting up my app as follows: 在阅读了几个SO问题之后,我最终如下设置了我的应用程序:
config.xml config.xml中
<allow-navigation href="*" />
<access origin="*" />
index.html 的index.html
<meta http-equiv="Content-Security-Policy" content="default-src 'self' http://server_ip:8080 data: gap: *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
of course, service_ip is the real server ip address and it accepts HTTP requests as I have been able to consume them using REST clients. 当然, service_ip是真实的服务器ip地址,它接受HTTP请求,因为我已经能够使用REST客户端使用它们。
Other considerations: 其他注意事项:
ionic run android
. 该应用程序是使用ionic run android
命令构建和启动的。 cordova-plugin-whitelist
. 我正在使用插件cordova-plugin-whitelist
。 (I removed and added it again following several SO answers... without success). (我删除并添加了几个SO答案后再次添加了它……没有成功)。 angular-resource
for HTTP requests. 还对HTTP请求使用插件angular-resource
。 Requests are correct as I have tested them using local machine ip and they work, problems came after changing that ip to the server ip . 请求是正确的,因为我已经使用本地计算机ip测试了请求,并且它们可以正常工作, 将IP更改为服务器ip后出现了问题 。 It looks like a CORS problem, I expected to solve it via meta
tag in index.html file but the behaviour is the same even when I set up: 它看起来像是一个CORS问题,我希望通过index.html文件中的meta
标签来解决它,但是即使设置了,行为也一样:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
Any help will be appreciated. 任何帮助将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.