android – Error Code 403 | Fetch Objects from iCloud Calendar by CalDAV | Flutter

Spread the love


I’m utilizing Flutter and Dart to be able to fetch Objects from my iCloud calendar by CalDAV protocol. I’ve already created an app-specific-password for my Apple account, certainly i’m utilizing that password to be able to login, i’m able to carry out appropriately each step contained in the “Retrieving calendar info” part as proven on this information, however i can’t proceed and fetch the objects as i get the error code 403.

The 403 Forbidden error signifies that the server understands the
request however cannot present extra entry.

That is the code i’m at present utilizing. I’m not certain if i needed to embody the c-tag contained in the request or not.

That is the official documentation of CalDAV.

Future<http.Response> fetchObjects() async {
  closing request = http.Request(
    'REPORT',
    Uri.parse('https://pXXX-caldav.icloud.com:XXX/3XX91XX0X/calendars'),
  );

  request.headers['Authorization'] =
      'Primary ' + base64Encode(utf8.encode('$appleId:$password'));
  request.headers['Depth'] = '1';
  request.headers['Prefer'] = 'return-minimal';
  request.headers['Content-Type'] = 'utility/xml; charset=utf-8';

  closing physique = '''
    <c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
    <d:prop>
        <d:getetag />
        <c:calendar-data />
    </d:prop>
    <c:filter>
        <c:comp-filter title="VCALENDAR" />
    </c:filter>
</c:calendar-query>
    ''';

  request.physique = physique;

  closing response = await request.ship();

  // Convert the StreamedResponse to a Response.
  closing convertedResponse = await response.stream.toBytes();
  closing parsedResponse =
      http.Response.bytes(convertedResponse, response.statusCode);

  print(parsedResponse.statusCode);
  print(parsedResponse.physique);
  return parsedResponse;
}

Leave a Reply

Your email address will not be published. Required fields are marked *