Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Displaying data sent via a node curl call in PHP
$ node test.js
stringified post: your=post&data=goes%20here
curl -d "your=post&data=goes%20here" -s "http://localhost:8888/post_demo.php"
stdout: post goes here
stderr:
<?php
echo $_POST["your"]." ".$_POST["data"];
?>
var util = require('util');
var exec = require('child_process').exec;
var querystring = require('querystring');
var params = {
"your":"post",
"data": "goes here"
};
var posts = querystring.stringify(params);
console.log('stringified post: ' + posts);
var command = 'curl -d "'+ posts +'" -s "http://localhost:8888/post_demo.php"'
console.log(command);
child = exec(command, function(error, stdout, stderr){
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if(error !== null)
{
console.log('exec error: ' + error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment