我想做的是 node.js
中的这个 curl 操作。
curl -XPOST localhost:12060/repository/schema/fieldType -H 'Content-Type: application/json' -d '
{
action: "create",
fieldType: {
name: "n$name",
valueType: { primitive: "STRING" },
scope: "versioned",
namespaces: { "my.demo": "n" }
}
}' -D -
欢迎提出建议。
最佳答案
通过这里http://query7.com/nodejs-curl-tutorial
Although there are no specific NodeJS bindings for cURL, we can still issue cURL requests via the command line interface. NodeJS comes with the child_process module which easily allows us to start processes and read their output. Doing so is fairly straight forward. We just need to import the exec method from the child_process module and call it. The first parameter is the command we want to execute and the second is a callback function that accepts error, stdout, stderr.
var util = require('util');
var exec = require('child_process').exec;
var command = 'curl -sL -w "%{http_code} %{time_total}\\n" "http://query7.com" -o /dev/null'
child = exec(command, function(error, stdout, stderr){
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if(error !== null)
{
console.log('exec error: ' + error);
}
});
编辑这也是一个可能的解决方案:https://github.com/dhruvbird/http-sync
关于javascript - 如何在 node.js 中执行此 curl 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7498648/