question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

axios.post sends a GET request

See original GitHub issue

Summary

This code should send a POST request, but sends a GET request ! It happens only when my app is deployed on my production server. But the bug happens before reaching the back-end so I don’t understand what is happening and why it is related to the environment. No problem on my local machine.

axios.post('/api/admin/tags/', formData)
         .then((response) => {
             console.log(response.data);
         })
         .catch((error) => {
             console.log(error.response.data);
         });

Context

  • axios version: v0.17.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:9

github_iconTop GitHub Comments

16reactions
ligne13commented, Jun 25, 2018

OK just found the solution ! https://stackoverflow.com/questions/47208440/axios-xmlhttprequest-is-sending-get-instead-of-post-in-production-environment

this was caused the trailing slash at the end of the request URI, which was causing a 301 redirect. The POST request was not visible in the XHR tab of Chrome’s debug console.

1reaction
fuqi1001commented, Aug 11, 2019

Same here, some api routes need tail ‘/’, I just skipped it and it automatically does a GET request

Read more comments on GitHub >

github_iconTop Results From Across the Web

axios.post is sending a GET request - Stack Overflow
I found this issue happens when Axios receives a 301 (Moved Permanently), because it makes a redirect but also changes the method to...
Read more >
How to make HTTP requests with Axios - LogRocket Blog
Making an HTTP request is as easy as passing a config object to the Axios function. You can make a POST request using...
Read more >
Axios tutorial - GET/POST requests in JavaScript with Axios
Axios makes it easy to send asynchronous HTTP requests to REST endpoints and perform CRUD operations. It can be used in plain JavaScript...
Read more >
Making HTTP requests with Axios - CircleCI
Axios works by making HTTP requests with NodeJS and XMLHttpRequests on the browser. If the request was successful, you will receive a response ......
Read more >
How to Perform HTTP Requests with Axios – A Complete Guide
Axios is a promise-based HTTP client for Node.js and the browser. Sending asynchronous HTTP queries to REST endpoints and performing CRUD ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found