N
N
nepster-web2013-12-21 21:50:26
PHP
nepster-web, 2013-12-21 21:50:26

How can I send post data and read it?

Actually, you need to transfer data to node via php.
I used the curl library

$curl = curl_init();
                    $data = array('message' => 'test');
                
                    curl_setopt($curl, CURLOPT_URL, "http://localhost:8888");
                    curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                
                    curl_exec($curl);

But further, please tell me how to read the data in the node?
var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  //, fs = require('fs')
  //, qs = require('querystring')

app.listen(8888);



console.log('START');

function handler(req, res) 
{
    console.log('HANDLER');

      console.log('STATUS: ' + res.statusCode);
      console.log('HEADERS: ' + res.headers);
     
 
     console.log("message: " + req.body.message);

    //console.log(res);
    
}

Somewhere along the docks I found this topic:
console.log("message: " + req.body.message);
However, the node crashes with an error not found
Please tell me how can I send the post data and read it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question