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

  • Home
  • SEARCH
  • 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 8733227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:36:29+00:00 2026-06-13T09:36:29+00:00

I am having trouble getting my node.js server to do an http POST request

  • 0

I am having trouble getting my node.js server to do an http POST request to another node.js server. I am fairly certain that the problem lies with the http library or how I am using it because I can write a small HTML page that performs the POST exactly as I want.

Here is how the server receiving the POST is set up

var server = restify.createServer({
   name: 'some server',
   version: "1.0.0"
});

server.use(restify.acceptParser(server.acceptable));
server.use(restify.bodyParser());    
server.post('/theurl/', handler.handlePost);

server.listen(config.port, function() {
   console.log("starting server on port %d", server.address().port);
});

Inside the handlePost method I am doing this:

exports.handlePost = function(req, res, next) {
   console.log("body: %s", JSON.stringify(req.body));
   console.log("params: %s", JSON.stringify(req.params));
}

Here is the how the server that is sending the POST is doing it (this was taken directly from the node.js http docs)

var options = {
   host: '127.0.0.1',
   port: 8090,
   path: '/theurl/',
   method: 'POST'
};

var req = http.request(options, function(res) {
   ses.setEncoding('utf8');
   res.on('data', function (chunk) {
      console.log('BODY: ' + chunk);
   });
});

req.on('error', function(e) {
   console.log('problem with request: ' + e.message);
});

req.write("<some>xml</some>");
req.end();

When I run the POST, both req.body and req.params are undefined inside the handlePost method.

But if I put the following HTML in a browser, I can post to the service just fine.

<html>
   <head>
     <script>
       function doPost()
       {
         var xmlhttp = new XMLHttpRequest();
         xmlhttp.open("POST","http://localhost:8090/theurl/",false);
         xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
         xmlhttp.send("<some>xml</some>");
       }
     </script>
   </head>
   <body>
      <button type="button" onclick="doPost()">POST data</button>   
   </body>
</html>

So am I doing something wrong with the node.js http library?

  • 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-13T09:36:30+00:00Added an answer on June 13, 2026 at 9:36 am

    Well, right after I posted this I realized that one thing I was doing in the HTML version that I wasn’t doing in the node.js version was setting the Content-Type on the request. If I change the options to this, it works:

    var options = {
       host: '127.0.0.1',
       port: 8090,
       path: '/theurl/',
       method: 'POST',
       headers: { "Content-type": "application/x-www-form-urlencoded" }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting the server to recognize a JSON POST request since I
I am trying to learn node.js, but I'm having trouble getting the simple server
im having trouble getting a string (containing a URL) from one activity to another.
Im having trouble getting my JTable that im using to display either check boxes
Having trouble getting my JQuery POST to be accepted by the WCF Service. Here's
Having trouble getting the oauth access token and secret exchanged from the request tokens
Having trouble getting my POST arrays to show all checkbox values from my form.
I am having trouble getting the node-mongodb-native drivers to play nice. I've installed everything,
Having trouble getting the id of divs on my page that begin with refresh.
I am having trouble getting Castle Dynamic Proxy to intercept methods that are explicit

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.