Created
May 16, 2011 08:29
-
-
Save chendrix/974096 to your computer and use it in GitHub Desktop.
Displaying data sent via a node curl call in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo $_POST["your"]." ".$_POST["data"]; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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