本文整理汇总了PHP中CHTTP::SetAdditionalHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP CHTTP::SetAdditionalHeaders方法的具体用法?PHP CHTTP::SetAdditionalHeaders怎么用?PHP CHTTP::SetAdditionalHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHTTP
的用法示例。
在下文中一共展示了CHTTP::SetAdditionalHeaders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SendCommand
private static function SendCommand($channelId, $message, $options = array())
{
if (!is_array($channelId))
$channelId = Array($channelId);
$channelId = implode('/', array_unique($channelId));
if (strlen($channelId) <=0 || strlen($message) <= 0)
return false;
$defaultOptions = array(
"method" => "POST",
"timeout" => 5,
"dont_wait_answer" => true
);
$options = array_merge($defaultOptions, $options);
if (!in_array($options["method"], Array('POST', 'GET')))
return false;
$nginx_error = COption::GetOptionString("pull", "nginx_error", "N");
if ($nginx_error != "N")
{
$nginx_error = unserialize($nginx_error);
if (intval($nginx_error['date'])+120 < time())
{
COption::SetOptionString("pull", "nginx_error", "N");
CAdminNotify::DeleteByTag("PULL_ERROR_SEND");
$nginx_error = "N";
}
else if ($nginx_error['count'] >= 10)
{
$ar = Array(
"MESSAGE" => GetMessage('PULL_ERROR_SEND'),
"TAG" => "PULL_ERROR_SEND",
"MODULE_ID" => "pull",
);
CAdminNotify::Add($ar);
return false;
}
}
$postdata = CHTTP::PrepareData($message);
$CHTTP = new CHTTP();
$CHTTP->http_timeout = intval($options["timeout"]);
if (isset($options["expiry"]))
{
$CHTTP->SetAdditionalHeaders(array("Message-Expiry" => intval($options["expiry"])));
}
$arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false);
if ($CHTTP->Query($options["method"], $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $options["dont_wait_answer"]))
{
$result = $options["dont_wait_answer"] ? '{}': $CHTTP->result;
}
else
{
if ($nginx_error == "N")
{
$nginx_error = Array(
'count' => 1,
'date' => time(),
'date_increment' => time(),
);
}
else if (intval($nginx_error['date_increment'])+1 < time())
{
$nginx_error['count'] = intval($nginx_error['count'])+1;
$nginx_error['date_increment'] = time();
}
COption::SetOptionString("pull", "nginx_error", serialize($nginx_error));
$result = false;
}
return $result;
}
示例2: createBlankFile
public function createBlankFile(array $fileData)
{
$accessToken = $this->getAccessToken();
$googleMimeType = $this->getInternalMimeTypeListByExtension(getFileExtension($fileData['name']));
$fileName = getFileNameWithoutExtension($fileData['name']);
CWebDavTools::convertToUtf8($fileName);
if (!$googleMimeType) {
return false;
}
$http = new CHTTP();
$http->http_timeout = 10;
$arUrl = $http->ParseURL('https://www.googleapis.com/drive/v2/files');
$http->SetAdditionalHeaders(array("Authorization" => "Bearer {$accessToken}"));
$postFields = "{\"title\":\"{$fileName}\",\"mimeType\":\"{$googleMimeType}\"}";
$postContentType = 'application/json; charset=UTF-8';
if (!$http->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postFields, $arUrl['proto'], $postContentType)) {
return false;
}
$this->checkHttpResponse($http);
// access token expired, let's get a new one and try again
if ($http->status == "401") {
//todo: invalid credential response
return false;
}
// error checking
if ($http->status != "200") {
return false;
}
$finalOutput = json_decode($http->result);
//last signed user must delete file from google drive
$this->insertPermission(array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id));
return array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id);
}