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.

Extra colon shows up while doing axios post

See original GitHub issue

I am trying to do post using axios in Node.js backend. While ‘get’ requests are working fine.r. As soon as i try ‘post’ method, this fails.

Below, i am trying to do a login whose backend in running as well (i have tested it all in postman).

const host = `http://localhost:6800/`;
function loginAdmin(email, password){
    return axios.post(`${host}admin/login`,JSON.stringify({email, password}));
}

As soon as this code runs, i find that i am trying to send {"email":"admin2@always.com","password":"1234"}:

a

You can see that extra ‘:’ here, which added i don’t know how.

Then i checked backend that what exactly i am receiving there, and i found:

 { '{"email":"admin2@always.com","password":"1234"}': '' }

Which means backend is receiving the data so cors problem does not exist, yet i am not able to understand the reason behind.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
SunGuoQiang123commented, Sep 10, 2019

if Content-Type: application/x-www-form-urlencoded;charset=UTF-8 , read the doc https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format

1reaction
priyankagupta34commented, Sep 10, 2019

I am providing valid javascript only. Latest ECMA script allows you to perform this way that if key and value variable is same in javascript, then we can use it this way. {email: email, password: password} can be written as {email, password}, why don’t you give it a shot in browser console 😃 However this is not the problem. It has got something to do with Content-Type: application/x-www-form-urlencoded;charset=UTF-8, as when i am doing urlendcoding, it then works. Still i don’t know what is this problem, am i suppose to continue like this const params = new URLSearchParams(); or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extra semicolon showing up in axios get request
However when the commented out, hard coded version runs it works just fine. At some point an extra semicolon is being added to...
Read more >
Understanding Axios POST requests - LogRocket Blog
Learn how to use the Axios POST method in both vanilla JavaScript and in a framework like React to send requests.
Read more >
Brand Partnership Guidelines - Axios
We punctuate branded posts the same way we punctuate editorial posts and words rarely appear in all-caps. ○ Axios body text is broken...
Read more >
Building a single-page application with Symfony 4, Vue.js ...
In this tutorial, we'll build a very simple application where users can post messages. We'll see how to: setup a development environment with...
Read more >
Making HTTP requests with Axios - CircleCI
If you don't have a CircleCI account, sign up for a free one here. ... Next I will show you how to do...
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