Cross Origin Resource sharing issue even when all the CORS headers are present

前端 未结 2 1001
無奈伤痛
無奈伤痛 2021-01-23 13:35

even though i have appended my service response with following provided CORS Headers :

resp.setContentType(\"application/json\");
resp.addHeader(\"Access-         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-23 13:44

    The preflight (OPTIONS) is occurring due to the fact that you are sending a cross-origin ajax request AND specifying an Authorization header with this GET request.

    Also (this is not causing an issue) I would suggest removing the contentType option. This doesn't make sense in the context of a GET request. A GET request should not have any content. All data should be included in the query string or, possibly, headers.

    The Authorization header will not be sent with the OPTIONS. You must acknowledge it server-side, and then the browser will send the underlying GET. Read more about CORS at https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS .

提交回复
热议问题