我有一个通过js-ipfs添加文件的函数。
async function addFile(url) {
try {
for await (const file of node.add(urlSource(url))) {
console.log('Hash for ' + url.substring(url.lastIndexOf('/') + 1));
}
}
catch(e) {
console.error('Problem downloading: ' + e.toString());
}
}我在工作中传递的一些URL非常好,而其他URL则只向某些用户代理提供文件。是否有一种方法可以在由IPFS urlSource完成的HTTP请求上指定"Wget/“的自定义用户代理
编辑:在浏览了一下js-ipfs的源代码之后,看起来它正在使用node-fetch来发出请求。我试着把台词改为:
for await (const file of node.add(urlSource(url, {"headers": ["User-Agent", "Wget/"]}))) {和
for await (const file of node.add(urlSource(url, {"headers": {"User-Agent": "Wget/"}}))) {基于文档,但没有骰子。Webhook.site仍然显示我的请求有一个node-fetch/1.0 (+https://github.com/bitinn/node-fetch)的用户代理。
https://stackoverflow.com/questions/61260762
复制相似问题