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

Comments

@geddski
Copy link

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

This comment has been minimized.

Copy link
Member

commented Sep 12, 2014

@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

This comment has been minimized.

Copy link
Member

commented Sep 12, 2014

@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 type:bug label Sep 14, 2014

@kentcdodds

This comment has been minimized.

Copy link

commented Sep 16, 2014

@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

This comment has been minimized.

Copy link
Author

commented Sep 16, 2014

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

@kentcdodds

This comment has been minimized.

Copy link

commented Sep 16, 2014

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

This comment has been minimized.

Copy link
Member

commented Sep 16, 2014

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

mzabriskie added a commit that referenced this issue Sep 17, 2014

@mzabriskie

This comment has been minimized.

Copy link
Member

commented Sep 17, 2014

@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.

@mzabriskie mzabriskie closed this Sep 17, 2014

@kentcdodds

This comment has been minimized.

Copy link

commented Sep 17, 2014

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

This comment has been minimized.

Copy link
Author

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)

@faztp12

This comment has been minimized.

Copy link

commented Sep 19, 2018

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.