XMLHttpRequest和Phonegap ...同源策略或不? [英] XMLHttpRequest and Phonegap... Same Origin Policy or not?

查看:224
本文介绍了XMLHttpRequest和Phonegap ...同源策略或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是新的Phonegap,我使用的Android SDK几天了。至少我想做一个 XMLHttpRequest 从我的服务器获取数据。
我知道同源策略之前,我问自己,这应该如何使用本机应用程序。

I'm still new to Phonegap and I am working with the Android SDK for some days now. At least I wanted to do a XMLHttpRequest to get data from my server. I knew about the Same Origin Policy before and I asked myself, how this should work with a "native app".

我搜索互联网,发现一些话题,人们告诉别人,Phonegap没有相同的原产地政策,因为它使用 file:// 协议,另外还有一个域白名单,它在 config.xml 中。

I searched the internet and found some topics, where people were telling others, that there is no Same Origin Policy on Phonegap, because it uses the file:// protocol and additionally there is a domain whitelist in it's config.xml.

另一方面,有一些主题的人有XHR的问题,有人告诉他们,这是因为同源政策...

On the other hand there were a bunch of topics of people having problems with XHR's and others told them, that this is because of the Same Origin Policy...

好吧,我很困惑,但我使用我的常规网站 - 工作 XMLHttpRequest 片段,并把它放入Phonegap app。我试过虚拟设备,但我的请求不工作。

Well, I was confused, but I used my - on regular websites - working XMLHttpRequest snippet and put it into the Phonegap app. I tried the virtual device, but my request is not working.

现在我问自己一些问题:

Now I asked myself some questions:


  • 谁是对的?在PhoneGap上是否有相同的原产地政策?

如果是:


  • 网域白名单中有哪些功能?

  • What function has that domain whitelist?

仍然可以取得伺服器资料的最佳方式是什么? / p>

What's the best way to still get the data of my server?

推荐答案

是的,人们是正确的只有在webApps

Yes, people are correct the Same Origin Policy is needed only in webApps not hybrid phonegap apps.

您需要检查您的域白名单,只需在 config.xml 中检查它 res - > xml 文件夹。

You need to check you domain whitelist, just check it in the config.xml in res --> xml folder.

xml web服务,您需要确保您的soap消息正确形成。请尝试捕获确切的错误。

For accessing xml web services you need to ensure your soap message is correctly formed. try to catch the exact error.

这篇关于XMLHttpRequest和Phonegap ...同源策略或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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