I have enabled cors by putting the following line in services.cfg
org.eclipse.smarthome.cors:enable=true
Is there anyway to enable such requests?
I have enabled cors by putting the following line in services.cfg
org.eclipse.smarthome.cors:enable=true
Is there anyway to enable such requests?
Now I have got it to work. The problem was with “content-type”:“application/json”. Browser sends a Preflight request when we want to send JSON using content-type application/json. The rest server was not accepting the header “content-type” therefore, POST request was not sent. The server code is in org.eclipse.smarthome.io.rest, I added the CORS filter as
responseContext.getHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, "content-type");
I rebuilt it and replaced the jar in openhab plugins.
Now, it is working fine. I think it is a bug in Eclipse Smarthome because POST JSON will not work without setting application/json and I don’t see any point not providing support for it.
I am going to open this issue there.
Better directly send a PR there! Thanks for the analysis!