Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

React Post请求跨域问题

  1. 前后端分离,前端ReactJS,后端PHP(Laravel), 本地调试的时候想调用远端接口。
  2. 前端配置:在pakcage.json中配置代理如下:
"proxy": "https://www.shufadict.com/api",
  1. 后端配置:Laravel添加中间件,配置允许跨域,如下:
header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Credentials: false");
        header("Access-Control-Allow-Methods: PUT, POST, GET, DELETE, OPTIONS");
        header("Access-Control-Allow-Headers: Content-Type, Access-Token, nonce, timestamp, packagename, sign, uuid");
        header("Access-Control-Expose-Headers: *");

结果,所有get请求都ok,但是post请求都返回如下错误:

Access to XMLHttpRequest at 'https://www.shufadict.com/' (redirected from 'http://localhost:3000/common/feedback') from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

求指点,困扰好几天了。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...