CORS 和 phonegap 应用程序 [英] CORS and phonegap apps

查看:30
本文介绍了CORS 和 phonegap 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

phonegap 应用程序是否需要任何 CORS 更改(例如设置 Access-Control-Allow-Origin:*)才能工作?我在 Heroku 上托管了一个 Restful API,想知道是否需要设置此标头才能让我的 phonegap 应用程序调用该服务?

Do phonegap applications require any CORS changes (like setting Access-Control-Allow-Origin:*) to work? I have a restful API hosted on Heroku and was wondering whether I need to set this header in order for my phonegap application to call the service?

我在想,因为 phonegap 应用程序并不是真正托管在域上,所以不需要 CORS 并且我不会遇到任何跨域问题?

I was thinking that because the phonegap application isn't really hosted on a domain, then CORS isn't required and I won't get any cross domain issues?

如果有人能向我解释为什么会这样或不是这样,那就太好了.

It would be great if someone could explain to me why this is or isn't the case.

推荐答案

PhoneGap 你可以只用 XHR 直接到远程服务器和它应该正常工作".跨域策略不适用于 PhoneGap(出于各种原因,基本上是因为您的应用程序本质上是在设备上运行 file://URI).

PhoneGap you can just XHR directly to remote servers and it should "just work". Cross-domain policy does not apply to PhoneGap (for a variety of reasons, basically because your app is essentially running off the file:// URI on-device).

请注意,您必须为您的应用设置白名单访问这些外部域.请检查此链接:

Please be aware that you will have to set up a whitelist for your apps to access these external domains. Please check this link:

http://docs.phonegap.com/en/1.8.0rc1/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

这篇关于CORS 和 phonegap 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆