我正在尝试使用 Axios 从我的 React 前端发送 POST 请求
import axios from 'axios'
axios.post('http://server:port/auth/login', {
username: 'admin',
password: 'MY_PASSWORD',
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error.response)
});
无论我做什么,我都会收到 400 Bad Request 响应,说明:
"username":[This field is required],
"password":[This field is required]
我在我的 Django 后端使用Django REST 框架进行身份验证。
使用 Insomnia 一切正常,但任何通过 React 的请求都会导致“错误请求”
django-cors-headers 也已安装和配置。
缥缈止盈
相关分类