Fiware error: Access-Control-Allow-Origin

与世无争的帅哥 提交于 2019-12-02 02:19:51

CORS requests are only supported by Orion Context Broker version 1.10 and above.

As @JoseManuelCantera has pointed out, you do not need to add any CORS specific headers to your request, those are handled by your client (browser, Postman etc.)

You need to:

  1. Upgrade your version to 1.10
  2. Start Orion in CORS mode

You can start Orion in CORS mode for any origin (Orion will accept CORS requests from any origin) as below:

contextBroker -corsOrigin __ALL

Please take a look at the CORS documentation for Orion for more information.

UPDATE

Please allow me to shortly explain CORS pre-flight logic. If your request is not a simple request, your browser will do a pre-flight request prior to yours with the OPTIONS method. If Orion is not started in CORS mode, you will always get method not allowed as a response to your non-simple requests.

So what is the problem, why are you getting different results with different clients? Postman (curl etc.) does exactly what you want it to do and sends the requests as you have configured. It does not check if the request you are sending should be pre-flighted or not.

On the other hand, your browser does check your request and do a pre-flight if necessary. You have no control over this other than modifying your request.

The Javascript framework you are working with is probably adding a header to the request rendering it a "non-simple" request. For example: X-Requested-With. Please see this question.

My suggestion is to take a look at the details of the request your browser sends (headers, methods etc.) and see what makes it a non-simple request. Then do the necessary changes on your js code to make sure your request falls within the scope of simple requests.

Having said that, you will need to upgrade your Orion version eventually since for example, a DELETE request is never going to be treated as a simple request when sent over a browser.

I think you need to upgrade to version 1.10 so that you can use CORS.

You do not need to add any header ;) and actually the Access-Control-Allow-Origing header is sent in the server response not by the client request

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