本文整理汇总了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");
}
}