最大CDN通过API清除

时间:2011-05-14 22:07:57

标签: php api

我正在尝试通过MaxCDN API清除文件,但它无法正常工作。这是我正在使用的代码。 print_r不会返回任何结果。

function purge() {
    date_default_timezone_set('America/Los_Angeles');
    $date = date('c');
    $apiid = 'myapiid';
    $apikey = 'myapi';
    $auth_key = hash('sha256', $date.':'.$apikey.':purge');
    $url = 'http://softsailor.alexdumitru.netdna-cdn.com/wp-content/themes/ss3/includes/sprite.jpg';
    if (!class_exists('IXR_Client')) {
        require_once (ABSPATH . WPINC . '/class-IXR.php');
    }
    $client = new IXR_Client('api.netdna.com','/xmlrpc/cache',80);
    $client->timeout = 30;
    $client->query('cache.purge', $apiid, $auth_string, $date, $url);
    print_r($client->getResponse());
}

我打开了调试,我收到以下错误     出了点问题 - -32300:传输错误 - HTTP状态代码不是200

2 个答案:

答案 0 :(得分:4)

嘿亚历克斯。我在MaxCDN工作,这是我从Wiki中获取的代码示例:

<?php
date_default_timezone_set('America/Los_Angeles');
include("lib/xmlrpc.inc");
$cur = date('c');
$apiKey = 'api-key';
$apiUserId = 'api-user-id';
$namespace = 'cache';
$method = 'purge';
$authString = hash('sha256', $cur . ':' . $apiKey . ':' . $method);

// this is the url to purge
$url= 'http://static.jdorfman.netdna-cdn.com/static/images/frugal-it-logo.png';
$f=new xmlrpcmsg("$namespace.$method", array(php_xmlrpc_encode($apiUserId),
php_xmlrpc_encode($authString), php_xmlrpc_encode($cur),
php_xmlrpc_encode($url)));
$c=new xmlrpc_client("/xmlrpc/cache", "api.netdna.com", 80,'http11');
$r=&$c->send($f);
print_r($r);
?>

如果您有任何其他问题或疑虑,请随时与我联系:jdorfman at maxcdn dot com

答案 1 :(得分:1)

jdorfman的示例转储整个原始响应,但如果你像我一样,你想用PHP将其转换为数据对象

以下是一些有用的提示:

$ r-&gt; serialize()仅访问原始XML响应

转换为JSON使用此:

$ xml = simplexml_load_string($ r-&gt; serialize());    echo json_encode($ xml);

相关问题