Slack incoming webhook: Request header field Content-type is not allowed by Access-Control-Allow-Headers in preflight response

前端 未结 2 1414
再見小時候
再見小時候 2020-12-06 01:42

I try to post a slack message via the fetch API in a browser:

fetch(\'https://hooks.slack.com/services/xxx/xxx/xx\', {
  method: \'post\',
  headers: {
    \         


        
2条回答
  •  [愿得一人]
    2020-12-06 01:45

    I am using axios and had similar issue. What worked for me is setting Content-Type header to application/x-www-form-urlencoded. found it in this thread: https://github.com/axios/axios/issues/475 It appears that this triggers "simple request" and therefore avoids triggering CORS preflight. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests

    HTH.

提交回复
热议问题