Ajax请求绕过了涟漪xhr代理

时间:2016-01-30 15:20:00

标签: ajax cordova proxy cors ripple

我一直在使用Ripple Emulator,但重新安装后,在请求跨域资源时不再使用XHR CORS代理。

我在Internet not accessible from ripple emulator

中尝试了建议的测试代码
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.

跨域代理设置为:local

似乎启动了代理:

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.

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

1 个答案:

答案 0 :(得分:0)

在其他帖子中,人们建议使用Chrome CORS扩展程序,但自Chrome 48起,所有CORS扩展程序似乎都停止了工作。

我在Visual Studio, Ripple Emulator and CORS/Cross Domain Ajax发布了此解决方法,但我将在下面再次概述:

  1. 在您的Chrome安装目录中 - 可能是C:\ Program Files(x86)\ Google \ Chrome \ Application - 创建chrome.exe的快捷方式
  2. 右键单击此快捷方式,然后选择“属性”
  3. 在“快捷方式”选项卡上的“目标”字段中,附加以下两个字段--allow-file-access-from-files --disable-web-security 4。保存此项并将快捷方式重命名为" Google Chrome - 使用Ripple"
  4. 进行调试
  5. 右键单击它并选择Pin to Start Menu
  6. 此快捷方式允许您在没有网络安全的情况下运行Chrome,这允许在Ripple中使用CORS。通过使用快捷方式,这不会影响您正常使用Chrome。现在为了使用Ripple

    1. 在Visual Studio中调试您的应用程序,该应用程序将在其自己的Chrome实例中启动Ripple
    2. 现在打开开始菜单,然后点击固定的"谷歌浏览器 - 使用Ripple进行调试"快捷键
    3. Chrome的第二个实例将启动并显示"您正在使用不受支持的命令行标记: - disable-web-security。稳定性和安全性将受到影响。"
    4. 将Ripple代理URL从Visual Studio实例复制到此新实例,例如http://localhost:4400/index.html?enableripple=cordova-3.0.0-NexusS
    5. 您的CORS请求现在可以在Ripple中使用。
    6. 请注意,Visual Studio刚刚用于启动Ripple。需要使用Chrome的开发人员工具进行调试。

      另请注意,您可以浏览到网址chrome:// version /

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

      请记住在设备上进行测试,但是一旦您确认您的应用正常运行,上述调试就更容易了。

相关问题