Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8421837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:15:38+00:00 2026-06-10T03:15:38+00:00

I have a nodejs app using bodyparser(), and this route : app.post(‘/users’, function(req, res){

  • 0

I have a nodejs app using bodyparser(), and this route :

app.post('/users', function(req, res){
  res.json(req.body)
})

when i curl

curl -X POST 127.0.0.1:3000/users -d 'name=batman'

server sends back this json :

{ name: 'batman' }

my problem is when trying to make the same request with http.request, req.body is empty
i’m doing the same call though, here is a test.js file that i run with node :

var http = require('http');

var options = {
  host: '127.0.0.1',
  port: 3000,
  path: '/api/users',
  method: 'POST'
};

var request = http.request(options, function (response) {
  var str = '';
  response.on('data', function (chunk) {
    str += chunk;
  });

  response.on('end', function () {
    console.log(str);
  });
});

request.end("name=batman");

request body is empty -> {}

why ? i’ve tried setting content-length but does not do anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:15:40+00:00Added an answer on June 10, 2026 at 3:15 am

    You need to pass a Content-Type to tell bodyParser() which parser to use. For regular form data, you should use Content-Type: application/x-www-form-urlencoded, so:

    var options = {
      host: '127.0.0.1',
      port: 3000,
      path: '/api/users',
      method: 'POST',
      'Content-Type': 'application/x-www-form-urlencoded'
    };
    

    Should do the trick.

    Edit: If you find yourself doing a lot of client HTTP requests in node, I heartily recommend Mikeal Rogers’ request module, which makes these things a breeze.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Expressjs w/ node.js and I have a route like this: users.init(app.db, function()
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I am completely lost on this; I am using NodeJS to fetch a JSON
I have the following Node.js directory structure. |--app/ |--app.js |--routers/ |--index.js/ |--models/ |--schemas.js |--post.js
I have an existing app written in PHP (using Kohana framework) and I want
I have a Node.js Express app that I'm hosting on Nodejitsu. I'm already using
I’m using Socket.IO with Node.js. I have an object socket which looks like this:
I have a node.js app using node-mysql to query a MySQL database. Problem: It
I have an iphone app using ASIHttpRequest. The server code is on heroku in
We have a popular web-app developed using CodeIgniter. Now we want to expose our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.