[在Visual Studio代码和Apache Royale上使用AMF时如何在Chrome上禁用CORS

问题描述 投票:1回答:1

[现在,我对将Remote Object与Apache Royale结合使用以通过Amfphp与我的服务器进行通信感到很感兴趣,我在CORS方面苦苦挣扎。

我第一次尝试使用SimpleRemoteObject是这样的错误:

Access to XMLHttpRequest at '*http://url_to_your_server/gateway.php*' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

[当我从本地启动我的应用程序,并使用AMF与我的服务器通信时,CORS阻止了请求,因为请求者的来源是本地主机而不是我的服务器域。

[经过google'ling之后,我找到了一个解决方案:启动带有某些特定参数的Chrome。这是我的launch.json文件:

{
    "configurations": [



        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome",
            "url": "${workspaceFolder}/bin/js-debug/index.html",
            "runtimeArgs": [
                "--disable-web-security"
             ],
            "webRoot": "${workspaceFolder}",
            "preLaunchTask": "build"
        }





    ]
}

您如何看待此解决方案?还有其他解决方案吗?

问候

visual-studio-code cors amf amfphp apache-royale
1个回答
0
投票

该解决方案适合本地测试。在生产中,royale客户端将与您的AMFPHP后端托管在同一域中,因此该问题将消失。实际上,通常您会将应用程序配置为在为Royale客户端提供服务的localhost中进行测试,这也将消除这种需要。

© www.soinside.com 2019 - 2024. All rights reserved.