【发布时间】:2015-03-20 05:59:19
【问题描述】:
我尝试解析 icloud 日历 (CalDav)。该日历可通过 webcal-protocol 访问。日历的地址看起来像webcal://p19-calendarws.icloud.com/ca/....
所以我的(希望是简单的)问题是:如何使用 webcal-protocol 发送请求?我用请求模块尝试过,但收到了错误消息[Error: Invalid protocol: webcal:] 而且 nativ http-module 似乎不适合。
编辑: 我尝试使用 http 模块: var url = "webcal://p19-calendarws.icloud.com/ca/**************";
var http = require('http');
http.get(url, function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
得到以下错误:Error: Protocol:webcal: not supported.
解决方案:
首先,我必须将日历地址中的webcal:// 替换为https://。 Apple 将重定向到日历的 icalendar 文件。由于重定向,我使用request 模块,它可以很好地处理重定向。
var request = require('request');
var calendarUrl = 'webcal://p19-calendarws.icloud.com/*****';
var options = {
url: calendarUrl.replace('webcal://', 'https://'),
gzip: true
};
request(options, function (error, response, icalData) {
console.log(icalData);
});
【问题讨论】:
-
你试过用普通的 http(s) 阅读它吗?唯一的其他选择是this。
-
是的,我尝试了 https 模块,它不起作用。您发布的库是 WebDav 服务器。但我需要一个使用 webcal 协议的 CalDav 客户端。
-
听起来像是编写 NPM 模块的机会。
-
@tschiela 它有一个 CalDav 客户端,目前正在开发中。所以它可能会也可能不会起作用。 github.com/mikedeboer/jsDAV/tree/master/lib/CalDAV
-
@Scorpion-Prince,什么是正确的开始方式?我考虑过使用 net-module。
标签: node.js protocols icalendar webcal