Ajax 请求绕过 ripple xhr 代理

Ajax requests bypass the ripple xhr proxy

我使用Ripple Emulator有一段时间了,但重装后请求跨域资源时不再使用XHR CORS代理

我已经尝试了建议的测试代码:

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://www.bing.com", true);
xmlhttp.send();

但是请求没有通过 Ripple XHR 代理传递。

要求:

GET / HTTP/1.1
Host: www.bing.com
Connection: keep-alive
Origin: http://localhost:4400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36
Accept: */*
Referer: http://localhost:4400/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: da,en;q=0.8,en-US;q=0.6

错误:

XMLHttpRequest cannot load http://www.bing.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4400' is therefore not allowed access.

跨域代理设置为:本地

好像启动了代理:

INFO: Server instance running on: http://localhost:4400
INFO: CORS XHR proxy service on: http://localhost:4400/ripple/xhr_proxy
INFO: JSONP XHR proxy service on: http://localhost:4400/ripple/jsonp_xhr_proxy
Cordova 3.0 Project detected...
INFO: Could not find cordova as a local module. Expecting to find it installed globally.
INFO: Using Browser User Agent (String)
refreshing project (platform: android) ...
... done.

对我在这里做错了什么有什么建议吗?

在其他帖子中,人们建议使用 Chrome CORS 扩展,但自从 Chrome 48 以来,所有 CORS 扩展似乎都已停止工作。

我在 上发布了这个解决方法,但我会在下面再次概述它:

  1. 在您的 Chrome 安装目录中 - 可能是 C:\Program Files (x86)\Google\Chrome\Application - 创建 chrome.exe
  2. 的快捷方式
  3. 右键单击此快捷方式和 select 属性
  4. 在“快捷方式”选项卡上的“目标”字段中附加以下两个字段 --allow-file-access-from-files --disable-web-security 4.保存并将快捷方式重命名为 "Google Chrome - Debug with Ripple"
  5. 右键单击它并select固定到开始菜单

此快捷方式将允许您 运行 Chrome 没有网络安全,这允许 Ripple 中的 CORS。通过使用快捷方式,这不会影响您正常使用 Chrome。现在为了使用 Ripple

  1. 在 Visual Studio 中调试您的应用程序,它将在其自己的 Chrome 实例中启动 Ripple
  2. 现在打开开始菜单并单击固定的 "Google Chrome - Debug with Ripple" 快捷方式
  3. Chrome 的第二个实例将以 "You are using an unsupported command-line flag: -- disable-web-security. Stability and security will suffer."
  4. 的警告启动
  5. 将 Ripple 代理 URL 从 Visual Studio 实例复制到这个新实例,例如 http://localhost:4400/index.html?enableripple=cordova-3.0.0-NexusS
  6. 您的 CORS 请求现在可以在 Ripple 中工作。

请注意,Visual Studio 刚刚用于启动 Ripple。需要使用 Chrome 的开发人员工具进行调试。

另请注意,您可以通过浏览到 url chrome://version/

来仔细检查 Chrome 是否正在使用您的快捷方式标志

记得还要在设备上进行测试,但是一旦您证明您的应用可以正常工作,上述内容就可以更轻松地进行日常调试。