简体   繁体   中英

What is the node.js equivalent of this curl request?

I'm trying to create a node app that can transmit data to a Motu audio device over HTTP.

I need a way to achieve the following in Node.js,

curl --data 'json={"mix/chan/0/matrix/fader":0}' voyager-audio-core.local/datastore

I tried the following, with no luck:

var request = require('request');

request.post(
    'voyager-audio-core.local/datastore',
    { "/mix/chan/0/matrix/fader" : 0 },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body)
        }
        console.log(response);
    }
);

Any suggestions?

This might be a syntax issue since the request() function only takes two arguments according to the docs . Does the following code work?

let options = {
  url: 'voyager-audio-core.local/datastore',
  body: 'json={"mix/chan/0/matrix/fader":0}'
}

request.post(options,
  function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log(body)
    }
    console.log(response);
  }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM