javascript - 正在获取 url

标签 javascript fetch icalendar

我正在尝试使用 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/

相关文章:

javascript - Ember.js 如何在没有 ember 数据的情况下从数组 Controller 中删除对象

Hibernate @OneToOne 即使使用 @Fetch(FetchMode.JOIN) 也会执行多个查询

react-redux - axios 与 fetch - 进行 api 调用时

calendar - 电子邮件中不显示回复按钮 - ical-generator

php - 这个 iCal 日历有什么问题?

javascript - 通过 websocket 发送时,JSON 将 Float32Array 缓冲区大小增加了很多倍

javascript - 在 Angularjs 的 2 个不同 Controller 中更新 $scope 时如何绑定(bind)和自动更新 View

javascript - 使用 array.splice() 第一个参数未定义,仍然有效

javascript fetch 无法捕获 404 错误

java - Java 的最佳 iCalendar 库?