我想做的是向这个本地 IP 地址发送请求,但它不断返回错误 404。我查看浏览器控制台,发现它重复了 url。
React + axios 代码:
import axios from "axios";
import { getToken } from "./auth";
const api = axios.create({
baseURL: '10.0.0.10:3333'
});
api.interceptors.request.use(async config => {
const token = getToken();
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
export default api;
组件代码
try {
const response = await api.post("/sessions", { email, password });
login(response.data.token);
this.props.history.push("/app");
} catch (err) {
this.setState({
error:
"Error"
});
最佳答案
我成功解决了这个问题。只需添加 http://10.0.0.10
And then install Axios
安装 CORS:
npm i cors
const cors = require ('cors')
app.use (cors ()) (put at the beginning)
关于reactjs - Axios 向重复的 url 发送帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65639496/