我正在开发google chrome扩展程序,我想在请求中发送标头,例如:
chrome.downloads.download({
url: 'http://test/api/file/download',
filename: "file_from_web_api.exe",
headers: {
ProfileID: "1"
}
});
但是我遇到了错误:
未捕获的TypeError:调用downloads.download(downloads.DownloadOptions选项,可选的函数回调)时出错:参数'options'中出错:属性'headers'中错误:类型无效:预期的数组,找到的对象。
我的问题是如何添加标题以下载请求
答案 0 :(得分:1)
根据docs标头需要为对象数组
chrome.downloads.download({
url: 'http://test/api/file/download',
filename: "file_from_web_api.exe",
headers: [
{'ProfileID': '1'}
]
});
您还可以先尝试创建标头对象,然后将其添加到数组look here
编辑:尝试使用标题对象
chrome.downloads.download({
url: 'http://test/api/file/download',
filename: "file_from_web_api.exe",
headers: new Headers({
'ProfileID': '1'
})
});