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

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

问题描述

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

我在互联网上搜索了一些主题,人们告诉其他人,Phonegap 没有同源策略,因为它使用 file:// 协议,另外还有一个域在它的 config.xml 中加入白名单.

另一方面,有很多人对 XHR 有问题,其他人告诉他们,这是因为同源政策......

好吧,我很困惑,但我在常规网站上使用了我的 - 工作 XMLHttpRequest 片段并将其放入 Phonegap 应用程序中.我尝试了虚拟设备,但我的请求不起作用.

现在我问自己一些问题:

  • 谁是对的?Phonegap 是否有同源政策?

如果是:

  • 该域白名单有什么功能?

  • 获取服务器数据的最佳方式是什么?

解决方案

是的,人们是对的

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

为了访问 xml Web 服务,您需要确保您的 soap 消息格式正确.尝试找出确切的错误.

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".

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.

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...

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:

  • Who is right? Is there Same Origin Policy on Phonegap or not?

If yes:

  • What function has that domain whitelist?

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

解决方案

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

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

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天全站免登陆