我正在尝试使用 ical npm 从特定的 ical url 检索内容。 我正在客户端测试这段代码。我已经设法获取了一些 icals。但这个和其他几个我没有。 它在 POSTMAN 上运行得很好。
我的代码是:
const ical = require('ical');
ical.fromURL('https://admin.vrbo.com/icalendar/5d19afbfbf144218a3c76eacf76267c6.ics', {mode: 'cors'}, (err, data) => {
console.log(err)
});
我得到的错误:
Error: Invalid value for opts.mode
at new push../node_modules/stream-http/lib/request.js.module.exports (request.js:58)
at Object.push../node_modules/stream-http/index.js.http.request (index.js:30)
at Object.push../node_modules/https-browserify/index.js.https.request (index.js:13)
at Request.push../node_modules/request/request.js.Request.start (request.js:829)
at Request.push../node_modules/request/request.js.Request.end (request.js:1639)
at end (request.js:628)
at request.js:644
at run (setImmediate.js:48)
at runIfPresent (setImmediate.js:83)
at onGlobalMessage (setImmediate.js:125)
请告诉我我做错了什么以及如何使这段代码工作。
最佳答案
我认为这里的问题是,您试图传递无效选项({mode: 'cors'}
)。 ical.fromURL(...)
将按原样将 options
参数传递给 request
(请参阅 Line 8 )。我检查了request的来源,但没有找到任何名为 mode
的选项(也许您将其与 Fetch API 混淆,因为有一个名为 mode
的选项),所以在我的意见,这也是您收到错误的原因(但我不确定为什么它对您有用,以获取其他一些日历)。您可以查看full list of possible options靠你自己。
关于javascript - 正在获取 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58885804/