本文整理汇总了PHP中HTTP_Request::addHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::addHeader方法的具体用法?PHP HTTP_Request::addHeader怎么用?PHP HTTP_Request::addHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::addHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportarDados
/**
* Método que encapsula a chamada do WEB SERVICE que traduz um arquivo .HTML em outras extensões.
* Utilizado para exportar dados para arquivos a desejo do usuário.
*
* @param texto $arquivoFetch nome do arquivo a ser utilizado para exportação, desde a pasta 'html'.
* @param texto $extensaoDestino mine type para arquivo exportado.
* @param texto $nomeArquivo nome a ser exibido no download do arquivo.
*/
function exportarDados($arquivoFetch, $nomeArquivo = "Relatório.pdf", $extensaoDestino = "application/pdf", $fazerDownload = true)
{
$codigoHtml = $this->smarty->fetch($arquivoFetch);
$codigoHtml = str_replace("html/css/", URL_COMPLETA . "html/css/", $codigoHtml);
$codigoHtml = str_replace("html/img/", URL_COMPLETA . "html/img/", $codigoHtml);
$request = new HTTP_Request(WEBSERVICE_BROFFICE_URL);
$request->setMethod("POST");
$request->addHeader("Content-Type", "text/html");
$request->addHeader("Accept", $extensaoDestino);
$request->setBody($codigoHtml);
$request->sendRequest();
$status = $request->getResponseCode();
//echo $request->getResponseBody(); die;
if ($status != 200) {
echo "Ocorreu um erro na conversão. Favor entrar em contato com o administrador.";
die;
}
if ($fazerDownload) {
header("Content-Type: " . $extensaoDestino . "\n");
header("Content-Disposition: attachment; filename=" . $nomeArquivo);
echo $request->getResponseBody();
die;
}
return $request->getResponseBody();
}
示例2: retrieveFile
/**
* Retrieves data from cache, if it's there. If it is, but it's expired,
* it performs a conditional GET to see if the data is updated. If it
* isn't, it down updates the modification time of the cache file and
* returns the data. If the cache is not there, or the remote file has been
* modified, it is downloaded and cached.
*
* @param string URL of remote file to retrieve
* @param int Length of time to cache file locally before asking the server
* if it changed.
* @return string File contents
*/
function retrieveFile($url, $cacheLength, $cacheDir)
{
$cacheID = md5($url);
$cache = new Cache_Lite(array("cacheDir" => $cacheDir, "lifeTime" => $cacheLength));
if ($data = $cache->get($cacheID)) {
return $data;
} else {
// we need to perform a request, so include HTTP_Request
include_once 'HTTP/Request.php';
// HTTP_Request has moronic redirect "handling", turn that off (Alexey Borzov)
$req = new HTTP_Request($url, array('allowRedirects' => false));
// if $cache->get($cacheID) found the file, but it was expired,
// $cache->_file will exist
if (isset($cache->_file) && file_exists($cache->_file)) {
$req->addHeader('If-Modified-Since', gmdate("D, d M Y H:i:s", filemtime($cache->_file)) . " GMT");
}
$req->addHeader('User-Agent', 'Firefox (WindowsXP) – Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
$req->sendRequest();
if (!($req->getResponseCode() == 304)) {
// data is changed, so save it to cache
$data = $req->getResponseBody();
$cache->save($data, $cacheID);
return $data;
} else {
// retrieve the data, since the first time we did this failed
if ($data = $cache->get($cacheID, 'default', true)) {
return $data;
}
}
}
Services_ExchangeRates::raiseError("Unable to retrieve file {$url} (unknown reason)", SERVICES_EXCHANGERATES_ERROR_RETRIEVAL_FAILED);
return false;
}
示例3: post
/**
* 投稿実行
*/
public function post()
{
$hr = new HTTP_Request($this->getPostUrl());
$hr->addHeader('X-WSSE', $this->wsse);
$hr->addHeader('Accept', 'application/x.atom+xml, application/xml, text/xml, */*');
$hr->addHeader('Authorization', 'WSSE profile="UsernameToken"');
$hr->addHeader('Content-Type', 'application/x.atom+xml');
$hr->addRawPostData($this->getRawdata());
$hr->setMethod(HTTP_REQUEST_METHOD_POST);
$hr->sendRequest();
$hr->clearPostData();
}
示例4: array
/**
* Create an HTTP_Request object and set all parameters necessary to
* perform fetches for this comic.
*
* @param timestamp $date Date of the comic to retrieve (default today)
*/
function _initHTTP($date, $url)
{
if (is_null($this->http)) {
$options = array();
if (isset($GLOBALS['conf']['http']['proxy']) && !empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) {
$options = array_merge($options, $GLOBALS['conf']['http']['proxy']);
}
require_once 'HTTP/Request.php';
$this->http = new HTTP_Request($url, $options);
$v = $this->getOverride("referer", $date);
if (!is_null($v)) {
$this->http->addHeader('Referer', $v);
}
$v = $this->getOverride("agent");
if (!is_null($v)) {
$this->http->addHeader('User-Agent', $v);
}
$user = $this->getOverride("user", $date);
$pass = $this->getOverride("pass", $date);
if (!is_null($user) and !is_null($pass)) {
$this->http->setBasicAuth($user, $pass);
}
foreach ($this->getOverride('cookies', $date) as $name => $value) {
$this->http->addCookie($name, $value);
}
foreach ($this->getOverride('headers', $date) as $name => $value) {
$this->addHeader($name, $value);
}
}
}
示例5: getRequest
/**
* @brief HTTP request 객체 생성
**/
function getRequest($url)
{
$oReqeust = new HTTP_Request($url);
$oReqeust->addHeader('Content-Type', 'application/xml');
$oReqeust->setMethod('GET');
return $oReqeust;
}
示例6: getRequest
/**
* @brief HTTP request 객체 생성
**/
function getRequest($url)
{
$oReqeust = new HTTP_Request($url);
$oReqeust->addHeader('Content-Type', 'application/xml');
$oReqeust->setMethod('GET');
$oReqeust->setBasicAuth($this->getUserID(), $this->getPassword());
return $oReqeust;
}
示例7: iconv
/**
* @brief rss 주소로 부터 내용을 받아오는 함수
*
* tistory 의 경우 원본 주소가 location 헤더를 뿜는다.(내용은 없음) 이를 해결하기 위한 수정
**/
function rss_request($rss_url)
{
// request rss
$rss_url = Context::convertEncodingStr($rss_url);
$URL_parsed = parse_url($rss_url);
if (strpos($URL_parsed["host"], 'naver.com')) {
$rss_url = iconv('UTF-8', 'euc-kr', $rss_url);
}
$rss_url = str_replace(array('%2F', '%3F', '%3A', '%3D', '%3B', '%26'), array('/', '?', ':', '=', ';', '&'), urlencode($rss_url));
$URL_parsed = parse_url($rss_url);
$host = $URL_parsed["host"];
$port = $URL_parsed["port"];
if ($port == 0) {
$port = 80;
}
$path = $URL_parsed["path"];
if ($URL_parsed["query"] != '') {
$path .= "?" . $URL_parsed["query"];
}
$oReqeust = new HTTP_Request($rss_url);
$oReqeust->addHeader('Content-Type', 'application/xml');
$oReqeust->addHeader('User-agent', 'RSS Reader Widget (XE ' . __ZBXE_VERSION__ . ' (http://www.xpressengine.com); PEAR HTTP_Request class (http://pear.php.net))');
$oReqeust->setMethod('GET');
$user = $URL_parsed["user"];
$pass = $URL_parsed["pass"];
if ($user) {
$oReqeust->setBasicAuth($user, $pass);
}
$oResponse = $oReqeust->sendRequest();
if (PEAR::isError($oResponse)) {
return;
}
$header = $oReqeust->getResponseHeader();
if ($header['location']) {
return $this->rss_request(trim($header['location']));
} else {
return $oReqeust->getResponseBody();
}
}
示例8: willRequest
function willRequest($request)
{
// お気に入り作成をフックする
if (preg_match("|^/favorites/create/(\\d+)|", $this->server->request['path'], $match)) {
$id = $match[1];
$url = $this->server->config['Twitter']['api'];
$url .= '/status/show/' . $id . '.json';
$req = new HTTP_Request($url);
if (isset($_SERVER["PHP_AUTH_USER"])) {
$req->setBasicAuth($_SERVER["PHP_AUTH_USER"], @$_SERVER["PHP_AUTH_PW"]);
}
$result = $req->sendRequest();
if (PEAR::isError($result)) {
return;
}
if ($req->getResponseCode() != 200) {
return;
}
$json = json_decode($req->getResponseBody());
$title = $json->text;
$href = 'http://twitter.com/' . $json->user->screen_name . '/status/' . $id;
$created = date('Y-m-d\\TH:i:s\\Z');
$nonce = pack('H*', sha1(md5(time())));
$pass_digest = base64_encode(pack('H*', sha1($nonce . $created . $this->server->config['Plugin']['HatenaBookmark']['password'])));
$wsse = 'UsernameToken Username="' . $this->server->config['Plugin']['HatenaBookmark']['id'] . '", ';
$wsse .= 'PasswordDigest="' . $pass_digest . '", ';
$wsse .= 'Nonce="' . base64_encode($nonce) . '",';
$wsse .= 'Created="' . $created . '"';
$req = new HTTP_Request('http://b.hatena.ne.jp/atom/post');
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader('WWW-Authenticate', 'WSSE profile="UsernameToken"');
$req->addHeader('X-WSSE', $wsse);
$req->addHeader('Content-Type', 'application/x.atom+xml');
$xml = '<?xml version="1.0" encoding="utf-8"?>' . '<entry xmlns="http://purl.org/atom/ns#">' . '<title>' . $title . '</title>' . '<link rel="related" type="text/html" href="' . $href . '" />' . '<summary type="text/plain"></summary>' . '</entry>';
$req->addRawPostData($xml);
$req->sendRequest();
}
return $request;
}
示例9: doHeadRequest
/**
* Send an HTTP HEAD request for the given URL
*
* @param string $url URL to request
* @param string &$errmsg error message, if any (on return)
* @return int HTTP response code or 777 on error
*
*/
function doHeadRequest($url, &$errmsg)
{
require_once 'HTTP/Request.php';
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_HEAD);
$req->addHeader('User-Agent', 'Geeklog/' . VERSION);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
$errmsg = $response->getMessage();
return 777;
} else {
return $req->getResponseCode();
}
}
示例10: sendNotification
function sendNotification($message, $regId)
{
$apikey = "AIzaSyDh3_C0r5OxdGGHN516XleJ1G_-aAMxEC4";
$rq = new HTTP_Request("https://android.googleapis.com/gcm/send");
$rq->setMethod(HTTP_REQUEST_METHOD_POST);
$rq->addHeader("Authorization", "key=" . $apikey);
$rq->addPostData("registration_id", $regId);
$rq->addPostData("collapse_key", "1");
$rq->addPostData("data.message", $message);
if (!PEAR::isError($rq->sendRequest())) {
print "\n" . $rq->getResponseBody();
} else {
print "\nError has occurred";
}
}
示例11: call
private function call($method, $args, $include_api_key = true)
{
$host = "rest.akismet.com";
if ($include_api_key) {
$host = "{$this->api_key}.{$host}";
}
$url = "http://{$host}/1.1/{$method}";
$req = new HTTP_Request($url, array("method" => "POST"));
$req->addHeader("User-Agent", "Cyberspace-Networks/" . PA_VERSION);
foreach ($args as $k => $v) {
$req->addPostData($k, $v);
}
$req->sendRequest();
return $req->getResponseBody();
}
示例12: post
/**
* Posts data to the URL
*
* @access public
* @param string $url URL address
* @param array $params Associated name/data values
* @param string $response Response body
* @return mixed Response code on success, otherwise Jaws_Error
*/
function post($url, $params = array(), &$response)
{
$httpRequest = new HTTP_Request($url, $this->options);
$httpRequest->addHeader('User-Agent', $this->user_agent);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
// add post data
foreach ($params as $key => $data) {
$httpRequest->addPostData($key, urlencode($data));
}
$result = $httpRequest->sendRequest();
if (PEAR::isError($result)) {
return Jaws_Error::raiseError($result->getMessage(), $result->getCode(), $this->default_error_level, 1);
}
$response = $httpRequest->getResponseBody();
return $httpRequest->getResponseCode();
}
示例13: _update
/**
* Submit REST Request to write data
*
* @param string $xml The command to execute
* @return mixed Boolean true on success or PEAR_Error
* @access private
*/
private function _update($xml)
{
global $configArray;
global $timer;
$this->client->setMethod('POST');
$this->client->setURL($this->host . "/update/");
if ($this->debug) {
echo "<pre>POST: ";
print_r($this->host . "/update/");
echo "XML:\n";
print_r($xml);
echo "</pre>\n";
}
// Set up XML
$this->client->addHeader('Content-Type', 'text/xml; charset=utf-8');
$this->client->addHeader('Content-Length', strlen($xml));
$this->client->setBody($xml);
// Send Request
$result = $this->client->sendRequest();
$responseCode = $this->client->getResponseCode();
//$this->client->clearPostData();
if ($responseCode == 500 || $responseCode == 400) {
$detail = $this->client->getResponseBody();
$timer->logTime("Send the update request");
// Attempt to extract the most useful error message from the response:
if (preg_match("/<title>(.*)<\\/title>/msi", $detail, $matches)) {
$errorMsg = $matches[1];
} else {
$errorMsg = $detail;
}
global $logger;
$logger->log("Error updating document\r\n{$xml}", PEAR_LOG_DEBUG);
return new PEAR_Error("Unexpected response -- " . $errorMsg);
} elseif ($configArray['System']['debugSolr'] == true) {
$this->client->getResponseBody();
$timer->logTime("Get response body");
// Attempt to extract the most useful error message from the response:
//print_r("Update Response:");
//print_r($detail);
}
if (!PEAR_Singleton::isError($result)) {
return true;
} else {
return $result;
}
}
示例14: PNB_getPingbackUrl
/**
* Get the Pingback URL for a given URL
*
* @param string $url URL to get the Pingback URL for
* @return string Pingback URL or empty string
*
*/
function PNB_getPingbackUrl($url)
{
require_once 'HTTP/Request.php';
$retval = '';
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_HEAD);
$req->addHeader('User-Agent', 'glFusion/' . GVERSION);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
COM_errorLog('Pingback (HEAD): ' . $response->getMessage());
return false;
} else {
$retval = $req->getResponseHeader('X-Pingback');
}
if (empty($retval)) {
// search for <link rel="pingback">
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader('User-Agent', 'glFusion/' . GVERSION);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
COM_errorLog('Pingback (GET): ' . $response->getMessage());
return false;
} elseif ($req->getResponseCode() == 200) {
$body = $req->getResponseBody();
// only search for the first match - it doesn't make sense to have
// more than one pingback URL
$found = preg_match("/<link rel=\"pingback\"[^>]*href=[\"']([^\"']*)[\"'][^>]*>/i", $body, $matches);
if ($found === 1 && !empty($matches[1])) {
$url = str_replace('&', '&', $matches[1]);
$retval = urldecode($url);
}
} else {
COM_errorLog('Pingback (GET): Got HTTP response code ' . $req->getResponseCode() . " when requesting {$url}");
return false;
}
}
return $retval;
}
示例15: Post
/**
* Post data to TypePad api server
*
* @access public
*/
function Post($method, $params, $apiKey = '')
{
$path = "/{$this->apiVersion}/{$method}";
if ($apiKey == '') {
$host = $this->apiServer;
} else {
$host = $apiKey . '.' . $this->apiServer;
}
$url = sprintf('http://%s:%s/%s/%s', $host, $this->apiPort, $this->apiVersion, $method);
require_once PEAR_PATH . 'HTTP/Request.php';
$options = array();
$timeout = (int) $GLOBALS['app']->Registry->fetch('connection_timeout', 'Settings');
$options['timeout'] = $timeout;
if ($GLOBALS['app']->Registry->fetch('proxy_enabled', 'Settings') == 'true') {
if ($GLOBALS['app']->Registry->fetch('proxy_auth', 'Settings') == 'true') {
$options['proxy_user'] = $GLOBALS['app']->Registry->fetch('proxy_user', 'Settings');
$options['proxy_pass'] = $GLOBALS['app']->Registry->fetch('proxy_pass', 'Settings');
}
$options['proxy_host'] = $GLOBALS['app']->Registry->fetch('proxy_host', 'Settings');
$options['proxy_port'] = $GLOBALS['app']->Registry->fetch('proxy_port', 'Settings');
}
$httpRequest = new HTTP_Request('', $options);
$httpRequest->setURL($url);
$httpRequest->addHeader('User-Agent', $this->userAgent);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_POST);
foreach ($params as $key => $data) {
$httpRequest->addPostData($key, urlencode(stripslashes($data)));
}
$resRequest = $httpRequest->sendRequest();
if (PEAR::isError($resRequest)) {
return new Jaws_Error($resRequest->getMessage());
} elseif ($httpRequest->getResponseCode() != 200) {
return new Jaws_Error('HTTP response error ' . $httpRequest->getResponseCode(), 'Policy', JAWS_ERROR_ERROR);
}
return $httpRequest->getResponseBody();
}