CORS Request(POST) - Custom Header doesn't work

One Star

CORS Request(POST) - Custom Header doesn't work

Hi,
I made a REST API (POST) for create a new ressource in the Database, and it works when I test it with Firefox RestClient.
But when I try to call the API from a web application, I got a CORS error. I tried to set custom headers in the tRestresponse's advanced setting, and got the pre-flight response (OPTIONS) which is 200 OK, but looking at its header, I didn't found what I set in the component tRestresponse. It seems that what I set is not valide.
So the question is: how to enable CORS for API (POST)?
Thanks in advances!
Moderator

Re: CORS Request(POST) - Custom Header doesn't work

Hi,
Are you using tRESTRequest? Could you please take a look at a jira issue:https://jira.talendforge.org/browse/TESB-10065 to see if it is what you are looking for?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Re: CORS Request(POST) - Custom Header doesn't work

I have the same issue and I am not using tRESTRequest. The client application makes a preflight request and the response is missing my custom headers. I am using Talend ESB Open Source 6.1.1. Is there a solution for this?

Re: CORS Request(POST) - Custom Header doesn't work

I ended up figuring out how to fix the issue. In tRESTRequest you have to create a separate entry with the same URL that uses the HTTP Verb OPTIONS. Then configure your headers to set the required CORS headers.
This is only required if your client application creates preflight requests.