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

查看:309
本文介绍了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天全站免登陆