Skip to content

Instantly share code, notes, and snippets.

@chendrix
Created May 16, 2011 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chendrix/974096 to your computer and use it in GitHub Desktop.
Save chendrix/974096 to your computer and use it in GitHub Desktop.
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