[英]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. 我正在尝试创建一个可以通过HTTP将数据传输到Motu音频设备的节点应用程序。
I need a way to achieve the following in Node.js, 我需要一种在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 . 这可能是一个语法问题,因为request()函数仅根据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);
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.