axios.post is sending a GET request

后端 未结 4 1533
清歌不尽
清歌不尽 2021-01-17 09:15

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 =         


        
相关标签:
4条回答
  • 2021-01-17 09:25

    In my case, My server use https

    so, http => https

    then problem solved.

    0 讨论(0)
  • 2021-01-17 09:25

    This happens then URL is redirected from POST call and GET happens after redirect. Most common redirects are caused by not needed trailing slashes or http redirecting to https

    0 讨论(0)
  • 2021-01-17 09:29

    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.

    0 讨论(0)
  • In general this happens because i) the original POST request is redirected by the server for some reason and ii) chrome dev tools hides the initial POST request for some unknown reason in this case. Typical issues are:

    • Lack of authentication leading to a 302 redirect.
    • Use of http which the server redirects to https with a 301 or 302.

    However there could be other reasons so you should inspect the HTTP requests going to your server to understand what's going on. A general tool like tcpflow is suitable. On nginx you can tail the access.log file. The idea is to understand what happens to the POST request so that the underlying issue can be corrected.

    0 讨论(0)
提交回复
热议问题