【发布时间】:2016-10-16 00:06:48
【问题描述】:
请帮助我在 Ionic2/Angular2 应用程序上使用 CORS。 我正在尝试使用 http 'GET' 请求获取数据。 当我在笔记本电脑上运行“$npm run build”时,我得到了预期的响应。 当我运行'$ cordova run android'时,我总是得到'Response with status: 0 for URL: null'。 这是代码sn-p:
this.http.get('https://httpbin.org/ip')
.subscribe((data: any) => {
this.result = data._body; // {"origin": "31.43.103.88"} on laptop
}, error => {
this.result = error; // 'Response with status: 0 for URL: null' on android
});
谢谢。
【问题讨论】:
-
您是否设法从浏览器访问您的 IP?验证端口是否也未被防火墙阻止。如果仍然无法正常工作,请参阅此帖子:stackoverflow.com/a/36124935/2549619