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 8363507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:11:33+00:00 2026-06-09T12:11:33+00:00

I wanna send JSON data in request body of POST method to a server

  • 0

I wanna send JSON data in request body of POST method to a server which will be written in node.js . I’ve tried a code like;

var http = require('http');
http.createServer(function (req, res) {
    console.log(req.body)
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

and I’ve tested it with curl as;

curl -i -v -X POST -d '{"a":5}' http://127.0.0.1:1337 -H "content-type:application/json"

But it says body is undefined.

Is there a way to get JSON data from request?

Thank!

  • 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-09T12:11:35+00:00Added an answer on June 9, 2026 at 12:11 pm

    Node.js is pretty low-level out of the box. Either you have to capture the request body yourself, or use something like connect.

    DIY:

    var http = require('http');
    http.createServer(function (req, res) {
        var body = '';
        req.on('data', function(data) {
            body += data;
        });
        req.on('end', function() {
            console.log(body);
        });
    }).listen(1337, '127.0.0.1');
    console.log('Server running at http://127.0.0.1:1337/');
    

    Connect:

    var connect = require('connect');
    connect()
        .use(connect.bodyParser())
        .use(function(req, res) {
            console.log(req.body);
        })
       .listen(3000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanna to use post function of jQuery to send data to php code,the
I wanna send data from client to server. There are two queues. in client
I wanna build a TCP/IP server that will be used by up to 100
In .NET CF 3.5 (on Windows CE 5.0), i wanna send receive data to/from
I am sending SMS by AT commands with GSM mobile phone. I wanna send
i wanna do a single selection in my table view here is my code
I wanna run selenium tests from TeamCity using Maven at Linux server without display.
I am developing a Facebook Application an i wanna send a video file from
i have this event handler Temp.MouseLeftButtonDown += new MouseButtonEventHandler(Temp_MouseLeftButtonDown); but i wanna send some
I wanna use swiftmailer to send the results of a form to a gmail

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.