reactjs - Axios 将帖子发送到重复的 url
问题描述
我想要做的是向这个本地 IP 地址发送一个请求,但它一直返回错误 404。我去查看浏览器控制台,它正在复制 url。
反应 + 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://”怎么样?
推荐阅读
- r - 如何在 R 中将 dicom 图像转换为 Jpg 格式
- postgresql - 如何访问服务器内部的 postgraphile 路由
- prometheus - 有例外的抑制(负匹配器)
- batch-file - 命令列出 Windows 中特定子文件夹中的所有 .java 文件
- anylogic - 运行一段时间后的概率容量 - ANYLOGIC
- android - “Android.Bluetooth.LE.AdvertiseFailure.DataTooLarge”在使用 AddServiceData 发送数据时出错
- colors - 在 Outlook 中同步颜色类别
- c - 如何在 ETAS OS 上运行的微控制器中获取日期信息?
- docker - Jira 在 1 个 docker 映像中带有插件
- symfony - Lexik JWT,如何只允许用户的信息