0

I'm currently trying to write a wordpress plugin that connects to a caldav server and creates an .ics file from the calendar data. as a first step, I used https://uname.pingveno.net/blog/index.php/post/2016/07/30/Sample-public-calendar-for-ownCloud-using-ICS-parser as a starting point, which works ok. But the wordpress admins refuse to accept a plugin that uses plain curl, they recommend doing it all through the WP http API: https://developer.wordpress.org/plugins/http-api/ . I managed to connect to the caldav server through that API, but can't get the desired xml response, only plain html, which does not contain the calendar data as such, but a table of .ics files, which would then have to be parsed individually, not very elegant... The problem seems to be how to implement these 3 lines:

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'REPORT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

via the wp API, especially:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'REPORT');

which does not seem to be possible via wp_remote_get() or wp_remote_post() . maybe anyone here got a hint for me ?

1 Answers1

0

just to answer my own question, the solution was to use wp_remote_request() instead of wp_remote_get() or wp_remote_post() because I needed the method 'REPORT':

$args = array(
    'headers' => array(
    'Authorization' => 'Basic ' . base64_encode( $calendar_user . ':' 
    . $calendar_password ),
    'Content-Type' => 'application/xml; charset=utf-8',
    'Depth' => '1',
    'Prefer' => 'return-minimal'),
'method' => 'REPORT',
'body' => $body,
);
$response = wp_remote_request( $calendar_url, $args );

which now works as expected. maybe anyone else here can use this...