-1
Good evening, I’m 2 days trying to send Curl php data to nodejs when I do out the Curl works... but I needed it to go this way.... attempt 1 php:
{
$this->ch = curl_init();
curl_setopt($this->ch,CURLOPT_URL, $url);
curl_setopt($this->ch,CURLOPT_POST, 1);
curl_setopt($this->ch,CURLOPT_POSTFIELDS, $data);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_POST, true);
$result = curl_exec($this->ch);
return curl_close($this->ch);
}
attempt 2:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//curl_setopt($ch, CURLOPT_PORT, 2403); //<----- Commented out !
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( //<--- Added this code block
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
var_dump($data);
$data = curl_exec($ch)|
in nodejs the post method in no way brings any kind of feedback that I’ve tried a little of everything and I’m missing ideas of how to do or what I’m doing wrong kkk wanted to send via post an xml to the nodejs treat but not even a basic send is going so I feel frustrated ... 4 days in trouble and I’m barely crawling on it ...
app.post('/teste', function (req, res,next) {
// console.log(util.inspect(req));
//console.log(util.inspect(req, false, null, true /* enable colors */));;
console.log(req.params);
console.log(req.query);
console.log('receiving data ...');
console.log('body is ',req.body);
res.send(req.body);
});
This method I can get the items and the returns are ok:
app.get('/agencia2', function (req, res,next) {
// console.log(req.params);
// console.log(req.body);
console.log(req.query);
console.log(req.query.id);
res.send("quase teste");
});
Why does it have to be at Curl? It is curious whether it works or has a specific reason?
– Augusto Vasques
how would you start the process of sending php information ( codeinginter) to nodejs? if you have any suggestions??
– Gustavo Castro
found in a stack post my question. https://stackoverflow.com/questions/10048978/sending-messages-from-php-to-node-js
– Gustavo Castro