node.jsprotocolsicalendarwebcal

How can i send a webcal request with node.js?


I try to parse an icloud calendar (CalDav). The calendar is accessible via webcal-protocol. The address of the calendar looks like webcal://p19-calendarws.icloud.com/ca/....

So my (hopefully easy) question is: How can i send a request with the webcal-protocol? I tried it with the request module, but got that error message [Error: Invalid protocol: webcal:] Also the nativ http-module seems not suitable for that.

Edit: My try with the http-module: 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);
    });

Get following error: Error: Protocol:webcal: not supported.

The Solution: First i have to replace the webcal:// with https:// in the calendar address. Apple will redirect to an icalendar file of the calendar. Because of the redirect i use the request module, which handles redirects very well.

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);
    });

Solution

  • WebCal is just http. All you have to do is to replace the scheme.

    The reason a different scheme was used, was so that browsers are able to easily use a different application to handle the request, but it's 100% a single HTTP request, and a GET. It's not DAV.