开发者

How do I do a `POST` with `Node.js`?

开发者 https://www.devze.com 2023-04-06 06:12 出处:网络
I\'ve followed examples and samples and everything and I am struggling.. the equivalent PHP code I\'m using is:

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.


request

var request = require("request");

request({
  url: "https://...",
  method: "POST",
  json: userArray
}, function _callback(err, res, body) {
  var result = body;
});
0

精彩评论

暂无评论...
验证码 换一张
取 消