我们有支持REST API的存储阵列。我可以通过邮递员完成所有操作(GET / POST / DELETE / PUT),并且需要通过Node.js脚本实现一个POST操作。
我在node.js GET操作中取得了成功。但仍然无法通过多种形式的多次尝试获得简单的POST操作。这是GET和PUT的代码。也是邮递员成功的POST操作截图。
感谢任何帮助。
var request = require('request');
function get_trustyou(trust_you_id, callback){
var options = {
url: 'https://xxxxxx/api/json/v2/types/consistency-groups',
rejectUnauthorized: false,
method: 'GET',
type: 'application/json',
auth:{
user: 'xxxxx',
pass: 'xxx'
}
};
var res = '';
request(options, function ( error, resp, body ) {
if ( !error && resp.statusCode == 200){
res = body;
}
if (error) {
console.log("this is error" + error);
}
callback(res);
});
}
get_trustyou("674fa44c-1fbd-4275-aa72-a20f262372cd", function(resp){
console.log("Here is the result" + resp);
});
var request = require('request');
function get_trustyou(trust_you_id, callback){
var options = {
body: postData,
url: 'https://xxxx/api/json/v2/types/consistency-groups',
rejectUnauthorized: false,
method: 'POST',
type: 'application/json',
auth:{
user: 'xxxx',
pass: 'xxxxx'
},
form: {
'consistency-group-name': 'TEST-CG'
}
};
request(options, function ( error, resp, body ) {
if ( !error && resp.statusCode == 200){
res = body;
}
if (error) {
console.log("this is error" + error);
}
callback(res);
});
}
get_trustyou("674fa44c-1fbd-4275-aa72-a20f262372cd", function(resp){
console.log("this is the responce" + resp);
});