我正在创建一个Web应用程序,该应用程序将在我无法管理或修改的服务器上运行。
在该应用程序中,我需要优先向其他服务器发送AJAX呼叫。 这将始终被“同源策略”阻止。
其中server01.test.net是网络服务器,mail.test.net是第二台服务器。
有没有办法在客户端以任何方式启用CORS,因为我无法在服务器上添加“Access-Control-Allow-Origin”*“'。 还是其他工作?
谢谢
I'm creating a web appliacation that will run on a server that I can not manage nor modify in any case.
Within that application, I need to exceute a AJAX call to a different server. This will always be blocked by the 'Same Origin Policy'.
Where server01.test.net is the webserver and mail.test.net is the second server.
Is there a way to enable CORS by any means in the client side, as I'm not able to add the 'Access-Control-Allow-Origin "*"' on the server. Or any other workaournd?
Thanks
最满意答案
如果您所调用的服务器不支持CORS,则您将无法使用AJAX向第三方服务器发送请求。
您将不得不求助于在应用程序中设置传递AJAX路线。 客户端(浏览器)向您的AJAX路由发出请求,该请求会将呼叫代理给第三方服务器并返回结果。 由于第三方请求发生在服务器而不是浏览器上,所以同源策略不适用。
这种方法意味着如果您可以使用CORS,将会出现一个额外的请求,但实际上没有其他选择。
If the server you are calling does not support CORS, you will not be able to make the request to the third-party server using AJAX.
You will have to resort to setting up a pass-through AJAX route in your application. The client (browser) makes a request to your AJAX route which proxies the call to the third-party server and returns the result. Because the third-party request is happening on the server rather than the browser, Same Origin Policy doesn't apply.
This approach means there will be an additional request that wouldn't be necessary if you could use CORS, but there really isn't another option.
在客户端启用CORS(Enabling CORS on the client side)我正在创建一个Web应用程序,该应用程序将在我无法管理或修改的服务器上运行。
在该应用程序中,我需要优先向其他服务器发送AJAX呼叫。 这将始终被“同源策略”阻止。
其中server01.test.net是网络服务器,mail.test.net是第二台服务器。
有没有办法在客户端以任何方式启用CORS,因为我无法在服务器上添加“Access-Control-Allow-Origin”*“'。 还是其他工作?
谢谢
I'm creating a web appliacation that will run on a server that I can not manage nor modify in any case.
Within that application, I need to exceute a AJAX call to a different server. This will always be blocked by the 'Same Origin Policy'.
Where server01.test.net is the webserver and mail.test.net is the second server.
Is there a way to enable CORS by any means in the client side, as I'm not able to add the 'Access-Control-Allow-Origin "*"' on the server. Or any other workaournd?
Thanks
最满意答案
如果您所调用的服务器不支持CORS,则您将无法使用AJAX向第三方服务器发送请求。
您将不得不求助于在应用程序中设置传递AJAX路线。 客户端(浏览器)向您的AJAX路由发出请求,该请求会将呼叫代理给第三方服务器并返回结果。 由于第三方请求发生在服务器而不是浏览器上,所以同源策略不适用。
这种方法意味着如果您可以使用CORS,将会出现一个额外的请求,但实际上没有其他选择。
If the server you are calling does not support CORS, you will not be able to make the request to the third-party server using AJAX.
You will have to resort to setting up a pass-through AJAX route in your application. The client (browser) makes a request to your AJAX route which proxies the call to the third-party server and returns the result. Because the third-party request is happening on the server rather than the browser, Same Origin Policy doesn't apply.
This approach means there will be an additional request that wouldn't be necessary if you could use CORS, but there really isn't another option.
发布评论