node.js - Can't send post to PHP script from nodejs and receive echo -
node.js - Can't send post to PHP script from nodejs and receive echo -
i got next code here
i've tried code variable data
beingness equal 'test=yes'
or data
beingness equal {test:'yes'}
here php script
if(isset($_post['test'])){ error_log("inside"); echo "and i'd homecoming this"; };
and here nodejs piece of code:
function posttophp(data, path){ var httpreq = require('http'); var querystring = require("querystring"); var info = querystring.stringify(data); var options = { host : 'localhost', path : 'www' + path, //path defined in actual code method : 'post', headers : { 'content-type' : 'application/x-www-form-urlencoded', 'content-length' : data.length } }; var buffer = ""; var reqpost = httpreq.request(options, function(res) { res.on('data', function(d) { buffer = buffer+data; }); res.on('end', function() { homecoming buffer; }); }); reqpost.write(data); reqpost.end(); }
and phone call of posttophp
//treat message? var message = "test=yes"; //or var message = "{test:'yes'}"; var buffer = posttophp(message,"path"); console.log("buffer php",buffer);
buffer
undefined
nothing shown in error log , assume not working code can't figure hope can help me figure 1 out.
php node.js
Comments
Post a Comment