Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

REST interface (POST) and CORS

Hello,
I have implement different REST interfaces. One interface for receiving data from a database. For that I use following schema:
0683p000009MBTV.png
Under tRestResponse I set Access-Control-Allow-Origin = *. That works fine. 
One interface I use for post data into in db. I use following schema:

0683p000009MBTa.png
Also under tRESTResponse I set Access-Control-Allow-Origin = *. But that not works. Under angularJS I also activate $http.defaults.headers.common = '*'; But in chrome/firefox I receive that error: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

Greets Benjamin

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hello, I had the same CORS issue when calling a Talend ESB REST Web Service, I solved it this way.0683p000009M5to.png
The Angular App running at http://localhost:4200 sends POST request that it preceded by a preflight OPTIONS request.

 

We have to configure in the tRESTRequest both HTTP verbs output flows namely POST and OPTIONS with the same URL (http://192.168.202.190:8090/sayHello/{name}).0683p000009M64R.png  
  • Headers to add in the "Component/Advanced Settings" tab of tRESTResponse for tRESTRequest OPTIONS Output Flow :
"Access-Control-Allow-Origin" : "*"
"Access-Control-Allow-Methods" : "OPTIONS"
"Access-Control-Allow-Headers" : "Access-Control-Allow-Origin, Accept, Content-Type"0683p000009M64W.png

 

  • Headers to add in the "Component/Advanced Settings" tab of tRESTResponse for tRESTRequest POST Output Flow :
"Access-Control-Allow-Origin" : "*"
"Access-Control-Allow-Methods" : "POST"
"Access-Control-Allow-Headers" : "Content-Type"

0683p000009M64b.png

 

  • Headers to add in the options of the Angular 6 POST Method :
'Content-Type': 'application/json'
'Accept': 'application/json'
'Access-Control-Allow-Origin': '*'

0683p000009M64g.png

 
That 's All you have to do to make it work fine !! !
It 's possible you get a CORB warning .

 

 

View solution in original post

4 Replies
Anonymous
Not applicable
Author

If a 1st service uses GET then it means it is a 'simple' CORS request.
If you have POST/PUT/DELETE then a browser will do a so-called preflight request first. You can add an OPTIONS flow handler to manage it. FYI a TESB JIRA exists to make this process smoother for the job designers 
Anonymous
Not applicable
Author

So I add OPTIONS flow for the same URI to an trestresponse and add "Access-Control-Allow-Methods" right?
Anonymous
Not applicable
Author

Yes please, add OPTIONS flow handler to tRESTRequest's URL Handler which will listen on the same URL where POST data will be sent to from a browser - the browser should issue a pre-flight OPTIONS request first - you may need to add few more headers to make it this pre-flight pass, see
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
which is one of the best articles.
HTH, Sergey
Anonymous
Not applicable
Author

Hello, I had the same CORS issue when calling a Talend ESB REST Web Service, I solved it this way.0683p000009M5to.png
The Angular App running at http://localhost:4200 sends POST request that it preceded by a preflight OPTIONS request.

 

We have to configure in the tRESTRequest both HTTP verbs output flows namely POST and OPTIONS with the same URL (http://192.168.202.190:8090/sayHello/{name}).0683p000009M64R.png  
  • Headers to add in the "Component/Advanced Settings" tab of tRESTResponse for tRESTRequest OPTIONS Output Flow :
"Access-Control-Allow-Origin" : "*"
"Access-Control-Allow-Methods" : "OPTIONS"
"Access-Control-Allow-Headers" : "Access-Control-Allow-Origin, Accept, Content-Type"0683p000009M64W.png

 

  • Headers to add in the "Component/Advanced Settings" tab of tRESTResponse for tRESTRequest POST Output Flow :
"Access-Control-Allow-Origin" : "*"
"Access-Control-Allow-Methods" : "POST"
"Access-Control-Allow-Headers" : "Content-Type"

0683p000009M64b.png

 

  • Headers to add in the options of the Angular 6 POST Method :
'Content-Type': 'application/json'
'Accept': 'application/json'
'Access-Control-Allow-Origin': '*'

0683p000009M64g.png

 
That 's All you have to do to make it work fine !! !
It 's possible you get a CORB warning .