2011-05-14 31 views
1

我想通過MaxCDN API清除文件,但它不工作。這是我正在使用的代碼。 print_r不會返回任何結果。通過API的最大CDN清除

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

回答

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在maxcdn點com

+0

我已經設法使用此示例Justin :) – Alex 2011-05-17 08:05:30

+0

您是否有.Net的工作示例?我正在使用來自NetDNA API頁面的示例,並且這兩種清除操作都不起作用。調用「purgeAllCache」返回「無效的認證字符串」(我敢肯定它不是),「清除」返回「無法解析請求」。 – jerhewet 2011-11-14 20:49:17

1

jdorfman的例子轉儲整個原始的反應,但如果你像我一樣,你想用PHP

這裏有一些有用的技巧把它轉換成數據對象:

$ R->連載()來訪問只是原始的XML迴應

轉換爲JSON使用此:

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