Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http not posting data in node #3

Closed
geddski opened this issue Sep 12, 2014 · 10 comments
Closed

http not posting data in node #3

geddski opened this issue Sep 12, 2014 · 10 comments

Comments

@geddski
Copy link

geddski commented Sep 12, 2014

axios({ 
  url: 'http://requestb.in/ubgv1aub',
  data: { test: true }
})

successfully posts but the request body is empty. Probably missing some headers, but setting Content-Type and Content-Length manually cause axios to hang for some reason.

@mzabriskie
Copy link
Member

@geddski you will need to specify the request method. If it's not specified it will default to GET.

axios({
  url: 'http://requestb.in/ubgv1aub',
  data: { test: true },
  method: 'post'
});

// or

axios.post('http://requestb.in/ubgv1aub', { test: true });

@mzabriskie
Copy link
Member

@geddski actually it looks like something is broken. Requests against my local server worked. Trying RequestBin I am getting 0 bytes transferred (I assume you're seeing the same). I will take a look at it tonight.

@mzabriskie mzabriskie added the bug label Sep 14, 2014
@kentcdodds
Copy link

@geddski, I looked into this and I believe it's an issue with RequestBin. First of all, when I try to post, I get a 503 from RequestBin which means "Service Unavailable." I used a different service called apiary.io and it works great. Try this:

var axios = require('axios');

var URL = 'http://kentcdodds.apiary-mock.com/random-user';
var BODY = {
  firstName: 'Joe',
  lastName: 'Moe'
};

function handleSuccess(data) { console.log(data); }
function handleFailure(data) { console.log('error', data); }

// GET
axios.get(URL, { params: BODY })
  .then(handleSuccess)
  .catch(handleFailure);

// POST
axios.post(URL, BODY)
  .then(handleSuccess)
  .catch(handleFailure);

This worked for me...

@geddski
Copy link
Author

geddski commented Sep 16, 2014

@kentcdodds maybe requestbin just requires an accurate content length, other services might as well

@kentcdodds
Copy link

oh, is that the problem?
On Sep 16, 2014 5:31 PM, "Dave Geddes" notifications@github.com wrote:

@kentcdodds https://github.com/kentcdodds maybe requestbin just
requires an accurate content length, other services might as well


Reply to this email directly or view it on GitHub
#3 (comment).

@mzabriskie
Copy link
Member

@kentcdodds @geddski I just added the Content-Length parameter and it seems to have done the trick.

@mzabriskie
Copy link
Member

@kentcdodds @geddski I've fixed the issue with Content-Length not being included. I did discover another issue (#9) while fixing this. So long as you are using JSON you will be unaffected.

@kentcdodds
Copy link

Nice
On Sep 16, 2014 5:46 PM, "Matt Zabriskie" notifications@github.com wrote:

@kentcdodds https://github.com/kentcdodds @geddski
https://github.com/geddski I just added the Content-Length parameter
and it seems to have done the trick.


Reply to this email directly or view it on GitHub
#3 (comment).

@geddski
Copy link
Author

geddski commented Sep 17, 2014

Sweet, nice work!!


Sent from Mailbox

On Tue, Sep 16, 2014 at 6:33 PM, Kent C. Dodds notifications@github.com
wrote:

Nice
On Sep 16, 2014 5:46 PM, "Matt Zabriskie" notifications@github.com wrote:

@kentcdodds https://github.com/kentcdodds @geddski
https://github.com/geddski I just added the Content-Length parameter
and it seems to have done the trick.


Reply to this email directly or view it on GitHub
#3 (comment).


Reply to this email directly or view it on GitHub:
#3 (comment)

@fahimalizain
Copy link

@mzabriskie
Everything works fine on browser,
but do not have POST payload on node

It started working once i manually specified Content-Type: application/json
Please have this documented / fixed for future devs :)

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants