-2

For the non simple cors request i am adding the following headers.

def testPostJSON(){


    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Credentials", "true");
    response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
    response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");

    render request.JSON.name

}

But you can see Access-Control-Allow-Headers is missing in the response headers. What is the reason it is missing? I am using Grails 2.2 for the server. Thanks for help!

enter image description here

kofhearts
  • 3,607
  • 8
  • 46
  • 79
  • is there any reason for down vote? is this not an appropriate question? – kofhearts Jul 17 '20 at 01:11
  • The response details shown in the question are for the response to the CORS preflight OPTIONS request that the browser automatically sends on its own, before even trying the actual request in your frontend JavaScript code. So you need to ensure that the server you’re sending the request to has the correct handling for OPTIONS requests — and specifically for CORS preflight OPTIONS requests. Given that the code currently shown in the question is for a `testPostJSON` function, maybe that code only gets executed for POST requests? – sideshowbarker Jul 18 '20 at 01:01
  • @sideshowbarker thanks! using the plugin solved it. maybe i was doing it wrong manually. – kofhearts Jul 18 '20 at 05:12
  • Cool — great to hear you got it working – sideshowbarker Jul 18 '20 at 05:16

1 Answers1

0

This plugin solved the problem.

https://grails.org/plugin/cors

kofhearts
  • 3,607
  • 8
  • 46
  • 79