Cross-Origin Request Blocked with React and Express

前端 未结 4 1194
长情又很酷
长情又很酷 2021-01-12 15:54

So I hit this error, when I was trying to send data to the back end using React. From what I learnt I need to allow the communication on the back-end and in the .htacc

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 16:21

    you have to allow OPTIONS method as well

    res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
    

    the browser send it with any post request to other domain to check how it will communicate with this remote server.

提交回复
热议问题