简体   繁体   English

Json-server 使用 React js 和 Redux 响应错误 404 not found Post Method

[英]Json-server responds Error 404 not found Post Method using React js and Redux

i get a error in my xhr network tab saying 'cannot POST /streams',i want to make a post request using axios and i have setup 'json-server',i have added db.json file and edited the script tag to我在我的 xhr 网络选项卡中收到一条错误消息,提示“无法 POST /streams”,我想使用 axios 发出一个发布请求,并且我已经设置了“json-server”,我添加了 db.json 文件并将脚本标签编辑为

"scripts": {"start": "json-server -p 3001 -w db.json"},

and i am dispatching an action,in that action i have written post method我正在调度一个动作,在那个动作中我写了 post 方法

export const add_Stream = (formValues) => async (dispatch) => {
 Streams.post("/streams", formValues);
};

Here is my db.json file data这是我的 db.json 文件数据

{
    "streams":[]
}

and i have created base url我已经创建了基础 url

import axios from "axios";

export default axios.create({
  baseUrl: "http://localhost:3001",
});

I think this happens because of your axios baseUrl params.我认为这是因为您的 axios baseUrl 参数而发生的。 Try this.尝试这个。 export default axios.create({ baseURL: "localhost:3001", });导出默认 axios.create({ baseURL: "localhost:3001", });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM