本文整理匯總了PHP中HttpClient::getResponseHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpClient::getResponseHeader方法的具體用法?PHP HttpClient::getResponseHeader怎麽用?PHP HttpClient::getResponseHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HttpClient
的用法示例。
在下文中一共展示了HttpClient::getResponseHeader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getArtistId
/**
* @param $name artist name
* @return spotify:artist:uri or false
*/
function getArtistId($name)
{
if (!$name) {
return false;
}
$url = 'http://ws.spotify.com/search/1/artist?q=' . urlencode($name);
$http = new HttpClient($url);
$http->setCacheTime(60 * 60 * 24);
//24 hours
$data = $http->getBody();
//TODO: use expire time for cached response
$expires = strtotime($http->getResponseHeader('Expires')) - time();
if ($http->getStatus() != 200) {
d('SpotifyMetadata->getArtistId server error: ' . $http->getStatus());
d($http->getResponseHeaders());
return false;
}
$arr = $this->parseArtists($data);
foreach ($arr as $a) {
if ($a['artist'] == $name) {
//d("exact match");
return $a['id'];
}
if (soundex($a['artist']) == soundex($name)) {
//d("fuzzy match");
return $a['id'];
}
}
return false;
}
示例2: parse
function parse($raw)
{
// TODO XmlReader should not handle HTTP protocol details
if (is_url($raw)) {
$url = $raw;
$h = new HttpClient($url);
// $h->setCacheTime('30m');
$raw = $h->getBody();
// d( $h->getResponseHeaders() );
if ($h->getStatus() == 404) {
// not found
return false;
}
if ($h->getStatus() == 302) {
$redir = $h->getResponseHeader('location');
// echo "REDIRECT: ".$redir."\n";
$h = new HttpClient($redir);
//XXX: reuse previous client?
$h->setCacheTime('30m');
$url = $redir;
$raw = $h->getBody();
}
// prepend XML header if nonexistent
if (strpos($raw, '<?xml ') === false) {
$raw = '<?xml version="1.0"?>' . $raw;
}
}
if (!$this->xml($raw)) {
if (isset($url)) {
throw new \Exception("Failed to parse XML from " . $url);
}
throw new \Exception("Failed to parse XML");
}
}