從CLI我可以下載的IBM沃森令牌,並將其保存爲文件token
:Node.js從一個帶有用戶名和密碼的URL下載文件?
curl -X GET --user username:password --output token
"https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api"
如何做到這一點的節點?我最好的猜測是:
var http = require('http');
var fs = require('fs');
var username = 'groucho';
var password = 'swordfish';
var header = {
// where does https go?
Host: 'stream.watsonplatform.net',
Path: '/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api',
Authorization: username:password
};
var download = function(header, dest, cb) {
var file = fs.createWriteStream("/javascript/services/token");
var request = http.get(header, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb); // close() is async, call cb after close completes.
});
}).on('error', function(err) { // Handle errors
fs.unlink(dest); // Delete the file async. (But we don't check the result)
if (cb) cb(err.message);
});
它是一個問題,問題是,服務器https
當我有節點設置爲http
?
你爲什麼不使用獲得令牌,只有令牌'https'模塊? – Joe