google-chrome-extension - 下载带有标题的文件请求 chrome 扩展
问题描述
我正在开发 google chrome 扩展程序,我想在请求中发送标头,例如:
chrome.downloads.download({
url: 'http://test/api/file/download',
filename: "file_from_web_api.exe",
headers: {
ProfileID: "1"
}
});
但我收到错误:
未捕获的类型错误:调用 downloads.download 时出错(downloads.DownloadOptions 选项,可选函数回调):参数“选项”错误:属性“标题”错误:无效类型:预期数组,找到对象。
我的问题是如何将headres附加到下载请求
解决方案
根据文档标题需要是一个对象数组
chrome.downloads.download({
url: 'http://test/api/file/download',
filename: "file_from_web_api.exe",
headers: [
{'ProfileID': '1'}
]
});
您也可以尝试先创建一个标头对象,然后将其添加到数组中看看这里
编辑:尝试使用标头对象
chrome.downloads.download({
url: 'http://test/api/file/download',
filename: "file_from_web_api.exe",
headers: new Headers({
'ProfileID': '1'
})
});
推荐阅读
- android - 在反应本机后台下载器中更改并发限制
- i2c - Rs485和I2C显示器一起使用
- python - Pandas - 根据 value_counts() 结果重新编码变量
- javascript - 为什么我得到一个带有 Promisify 的 TypeError
- javascript - 如何在用javascript返回结果之前完成.map?
- angular - Angular 中的类型化管道
- c# - 如何在 Rx.Net 中使用异步累加器实现 ScanAsync 运算符?
- csv - Perl 解析 csv 文件并迭代 curl
- powershell - Get-WinEvent - 展开属性 $_.Message 以获取完整的消息详细信息?
- integer-overflow - dafny 建模整数溢出