我正在使用promise-promise-native程序包,但是在处理响应时遇到困难。我知道我的URL和身份验证是正确的,当我打印响应时,我什至可以看到我要下载的文件。
const rp = require('request-promise-native');
let jarFile = fs.createWriteStream('something.jar');
const options = {
uri: urlLink,
auth: auth,
resolveWithFullResponse: true,
encoding: null,
};
rp(options)
.then(function (response) {
console.log('This is the response object: ', response);
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
jarFile.write(response.body);
})
.catch(function (error) {
console.log(`This was the error that was given: ${error}. `);
});
在查看控制台时,我知道我的请求是正确的,但无法存储.jar文件。即使我打印
console.log(response.body);
在命令行中,得到的只是一个空字符串。但是当我键入
console.log(response);
在命令行中,我看到它在那里。
有什么想法吗?