React的Reqwest的post请求方式的使用
一、前端代码(加个headers)
headers: { "Content-Type": "application/json", // "Access-Control-Request-Headers": "Origin, X-Requested-With, Content-Type, Accept" },
二、后端代码(也加请求头)
1.
2.
3.代码:
4.// 允许跨域访问 5. header('Access-Control-Allow-Origin: *'); 6. header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization"); 7. header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); |
三、使用