【问题标题】:caldav wordpress plugin without curl, using wp_remote_get() instead没有 curl 的 caldav wordpress 插件,使用 wp_remote_get() 代替
【发布时间】:2018-11-13 09:00:50
【问题描述】:

我目前正在尝试编写一个连接到 caldav 服务器并从日历数据创建 .ics 文件的 wordpress 插件。 作为第一步,我使用https://uname.pingveno.net/blog/index.php/post/2016/07/30/Sample-public-calendar-for-ownCloud-using-ICS-parser 作为起点,它工作正常。 但是 wordpress 管理员拒绝接受使用普通 curl 的插件,他们建议通过 WP http API 完成所有操作:https://developer.wordpress.org/plugins/http-api/。 我设法通过该 API 连接到 caldav 服务器,但无法获得所需的 xml 响应,只有纯 html,其中不包含日历数据,而是 .ics 文件表,然后必须是单独解析,不是很优雅...... 问题似乎是如何实现这 3 行:

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

通过 wp API,尤其是:

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

这似乎无法通过 wp_remote_get() 或 wp_remote_post() 实现。 也许这里有人给我提示?

【问题讨论】:

    标签: php wordpress curl caldav


    【解决方案1】:

    只是为了回答我自己的问题,解决方案是使用 wp_remote_request() 而不是 wp_remote_get() 或 wp_remote_post() 因为我需要方法 '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 );
    

    现在按预期工作。 也许这里的其他任何人都可以使用它...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 2016-06-10
      相关资源
      最近更新 更多