本文整理匯總了PHP中HTTPRequest::addHeaders方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTTPRequest::addHeaders方法的具體用法?PHP HTTPRequest::addHeaders怎麽用?PHP HTTPRequest::addHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::addHeaders方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: deleteFile
/**
* 刪除文件,要auth認證
* @example shell curl -i -H 'Authorization: QBox asdf' 'http://rs.qbox.me/delete/asdf'
* @return boolean
*/
public function deleteFile($remoteFileName)
{
$remoteFileName = str_replace('/', '', $remoteFileName);
$uri = 'http://' . str_replace('//', '/', $this->conf['host']['rs'] . '/delete/') . $this->encode($this->bucket . ':' . $remoteFileName);
$policy = array('scope' => $this->bucket, 'deadline' => time() + 3600);
$tmp = parse_url($uri);
$auth = $this->sign($tmp['path'] . "\n");
$http = new \HTTPRequest($uri, HTTP_METH_POST);
$http->addHeaders(array('Authorization' => 'QBox ' . $auth));
$r = $http->send();
$body = json_decode($http->getResponseBody(), true);
$code = $http->getResponseCode();
//612是文件不存在
if ($code == 200 || $code == 612) {
return true;
}
throw new Exception($body['error'], $code);
}
示例2: decode
public function decode($point = array('lat' => null, 'lng' => null))
{
$uri = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=' . $point['lat'] . ',' . $point['lng'];
$http = new \HTTPRequest($uri, HTTP_METH_GET);
if (isset($this->conf['lang'])) {
$http->addHeaders(array('Accept-Language' => $this->conf['lang']));
}
$http->send();
$code = $http->getResponseCode();
if ($code != 200) {
throw new Exception('http error', $code);
}
$r = json_decode($http->getResponseBody(), true);
if (!isset($r['results'][0]['formatted_address'])) {
throw new Exception($r['status'], -1);
}
return array('address' => $r['results'][0]['formatted_address']);
}