axios.post 正在发送 GET 请求 [英] axios.post is sending a GET request

查看:39
本文介绍了axios.post 正在发送 GET 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 react/axios 的 chrome 扩展.在那个应用程序中,我发送了一个像这样的帖子请求:

I have a chrome extension which uses react/axios. In that app I'm sending a post request like so:

export const createComment = payload => {
  const url = `${COMMENTS_BASE_URL}`;
  const promise = axios.post(url, payload);
  return { type: CREATE_COMMENT, promise };
}

尽管很明显是 axios.post(),但浏览器正在向 url 发送 GET 请求,这是不允许的(响应 405).我也尝试过使用 axios({ method: 'post', ... }) 但浏览器发送 GET 请求也会发生同样的事情.

Even though it's clearly axios.post(), the browser is sending a GET request to the url, which is not allowed (response 405). I've tried also using axios({ method: 'post', ... }) but the same thing happens with the browser sending a GET request.

推荐答案

如果有的话,尝试删除 COMMENTS_BASE_URL 中的尾部斜杠.即使用/resource"而不是/resource/".我们遇到了同样的问题.

Try to remove a trailing slash in COMMENTS_BASE_URL if you have it. i.e. use '/resource' instead of '/resource/'. We had the same problem.

这篇关于axios.post 正在发送 GET 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆