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