尝试使用javascript执行第一次Rest调用。我的代码如下:
var https = require('https');
var user = '<Domain>\\*****';
var pass = '******';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
/**
* HOW TO Make an HTTP Call - GET
*/
// options for GET
var optionsget = {
host : '**************', // here only the domain name
// (no http/https !)
port : 443,
path : '/rest/api/latest/plan/dummy1/branch', // the rest of the url with parameters if needed
method : 'GET', // do GET
'Content-Type': 'application/json',
Accept: 'application/json',
auth : {
username: user,
password: pass
}
};
console.info('Options prepared:');
console.info(optionsget);
console.info('Do the GET call');
// do the GET request
var reqGet = https.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
// uncomment it for header details
console.log("headers: ", res.headers);
res.on('data', function(d) {
console.info('GET result:\n');
process.stdout.write(d);
console.info('\n\nCall completed');
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
但是上面会产生如下错误。请帮助理解这个问题以及如何解决它?
进行GET通话 *** buffer.js:202 抛出新的TypeError(kFromErrorMsg); ^
TypeError:第一个参数必须是字符串,Buffer,ArrayBuffer,Array或类似数组的对象。
at Function.Buffer.from (buffer.js:202:9)
at new ClientRequest (_http_client.js:198:27)
at Object.request (http.js:38:10)
at Object.request (https.js:239:15)
at Object.<anonymous> (C:\som_temp\test.js:49:20)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)***