Cross Origin Resource Sharing - CORS

℡╲_俬逩灬. 提交于 2019-12-25 18:55:12

问题


Trying to make a cross origin call from one server to another server. Cant get it working. So made a test page with the code that works with this example http://arunranga.com/examples/access-control/preflightInvocation.html

Here is my example page with same code: http://webcosmo.com/test.html

However I am getting 403 forbidden error.

Anybody?


回答1:


Your resource is missing Access-Control-Allow-Origin header. Thus CORS won't work with it. Try adding this to your response headers:

Access-Control-Allow-Origin: *

Read this for more info about Access-Control-Allow-Origin header.




回答2:


if you add Access-Control-Allow-Origin: * then your instruction withCredentials wont work. The best practice is to add direct origin from request. In PHP you can use $_SERVER['HTTP_ORIGIN'];

p.s. also you can compare origins with your trusted domains and give limited access.



来源:https://stackoverflow.com/questions/14565618/cross-origin-resource-sharing-cors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!