直接贴代码
$urls = array(
"",
"",
""
);
$data =array(
"username" => $this->cdnUserName,
"password" => $this->cdnPwd
) ;
$data['task'] = json_encode(
array(
'urls' => $urls
)
);
$data = http_build_query($data);
$url = "https://r.chinacache.com/content/refresh";
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($curl);
if (curl_errno($curl)) {
//to do...
} else {
//to do...
}
curl_close($curl);
期间curl报了:Couldn't resolve host 'r.chinacache.com'错误信息,用nslookup查看
# nslookup r.chinacache.com
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached
解决方式为
# vi /etc/resolv.conf
nameserver 8.8.8.8
保存退出
再用nslookup查看
# nslookup r.chinacache.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: r.chinacache.com
Address: 101.251.97.214