Pregunta

I've followed examples and samples and everything and I am struggling.. the equivalent PHP code I'm using is:

$url = json_encode($userArray);

$postURL = "https://mysite.com/v4/bulk?api_key=51076b4234e62c7b4ef8e33717a3bce5";
$ch = curl_init($postURL);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ( 'Content-Type: application/json'));
curl_setopt ($ch, CURLOPT_POSTFIELDS,$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$result = json_decode($result, true);

I just can't get this to work within Node. Any help would be greatly appreciated.

Thanks.

¿Fue útil?

Solución

request

var request = require("request");

request({
  url: "https://...",
  method: "POST",
  json: userArray
}, function _callback(err, res, body) {
  var result = body;
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top