当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Http_Client::setHeaders方法代码示例

本文整理汇总了PHP中Zend_Http_Client::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::setHeaders方法的具体用法?PHP Zend_Http_Client::setHeaders怎么用?PHP Zend_Http_Client::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Http_Client的用法示例。


在下文中一共展示了Zend_Http_Client::setHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _api_request

 protected function _api_request($method, $path, $data = null)
 {
     $url = trim($this->getBaseApiUrl(), "/") . self::API_CHECKOUT_PATH . $path;
     $client = new Zend_Http_Client($url);
     if (in_array($method, array(Zend_Http_Client::POST, Zend_Http_Client::PUT, 'PATCH')) && $data) {
         $client->setHeaders('Content-type: application/json');
         $client->setRawData(json_encode($data), 'application/json');
     }
     $client->setHeaders('Authorization: Bearer ' . Mage::getStoreConfig('payment/aplazame/secret_api_key'));
     $client->setHeaders('User-Agent: ' . self::USER_AGENT);
     $client->setHeaders('Accept: ' . 'application/vnd.aplazame' . (Mage::getStoreConfig('payment/aplazame/sandbox') ? '.sandbox-' : '-') . Mage::getStoreConfig('payment/aplazame/version') . '+json');
     $response = $client->request($method);
     $raw_result = $response->getBody();
     $status_code = $response->getStatus();
     if ($status_code >= 500) {
         Mage::throwException(Mage::helper('aplazame')->__('Aplazame error code: ' . $status_code));
     }
     try {
         $ret_json = Zend_Json::decode($raw_result, Zend_Json::TYPE_ARRAY);
     } catch (Zend_Json_Exception $e) {
         Mage::throwException(Mage::helper('aplazame')->__('Invalid api response: ' . $raw_result));
     }
     if ($status_code >= 400) {
         Mage::throwException(Mage::helper('aplazame')->__('Aplazame error code ' . $status_code . ': ' . $ret_json['error']['message']));
     }
     return $ret_json;
 }
开发者ID:jgermade,项目名称:magento,代码行数:27,代码来源:Client.php

示例2: _request

 /**
  * 
  */
 protected function _request($url, $params, $method = Zend_Http_Client::GET)
 {
     $this->_client->setUri($url)->resetParameters();
     if (count($params['header'])) {
         foreach ($params['header'] as $name => $value) {
             $this->_client->setHeaders($name, $value);
         }
     }
     if (count($params['post'])) {
         foreach ($params['post'] as $name => $value) {
             $this->_client->setParameterPost($name, $value);
         }
     }
     if (count($params['get'])) {
         foreach ($params['get'] as $name => $value) {
             $this->_client->setParameterGet($name, $value);
         }
     }
     if (count($params['json'])) {
         //$this->_client->setHeaders('Content-type','application/json');
         $rawJson = json_encode($params['json']);
         //$this->_client->setRawData($rawJson);
         $this->_client->setRawData($rawJson, 'application/json');
     }
     $response = $this->_client->request($method);
     $result = $response->getBody();
     #echo $result . "\n\n <br>";
     return json_decode($result);
 }
开发者ID:rtsantos,项目名称:mais,代码行数:32,代码来源:Ice.php

示例3: _fetch

 protected function _fetch(Mzax_GeoIp_Request $request)
 {
     $uri = str_replace('{IP}', $request->ip, self::API_URI);
     $client = new Zend_Http_Client($uri);
     $client->setHeaders('tool', 'PHP Mzax_GeoIp Lib');
     $client->setHeaders('tool_version', 'v1.0.1');
     try {
         $response = $client->request();
         $request->httpResponse = $response;
         $data = Zend_Json::decode($response->getBody());
         if (isset($data['city'])) {
             $request->city = $data['city'];
         }
         if (isset($data['region'])) {
             $request->region = $data['region'];
         }
         if (isset($data['country'])) {
             $request->countryId = $data['country'];
         }
         if (isset($data['loc'])) {
             $request->loc = explode(',', $data['loc']);
         }
         if (isset($data['org'])) {
             $request->org = $data['org'];
         }
     } catch (Zend_Json_Exception $e) {
         $this->easeTillNextDay();
         throw $e;
     }
 }
开发者ID:jsiefer,项目名称:emarketing,代码行数:30,代码来源:Ipinfo.php

示例4: execute

 protected function execute($arguments = array(), $options = array())
 {
     require_once realpath(dirname(__FILE__) . '/../../../../lib/vendor/OAuth/OAuth.php');
     new sfDatabaseManager($this->configuration);
     sfContext::createInstance($this->createConfiguration('pc_frontend', 'prod'), 'pc_frontend');
     $consumerKey = isset($options['consumer-key']) && $options['consumer-key'] ? $options['consumer-key'] : opOpenSocialToolKit::getOAuthConsumerKey();
     $consumer = new OAuthConsumer($consumerKey, null, null);
     $signatureMethod = new OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin();
     $httpOptions = opOpenSocialToolKit::getHttpOptions();
     $queueGroups = Doctrine::getTable('ApplicationLifecycleEventQueue')->getQueueGroups();
     $limitRequest = (int) $options['limit-request'];
     $limitRequestApp = (int) $options['limit-request-app'];
     $allRequest = 0;
     foreach ($queueGroups as $group) {
         $application = Doctrine::getTable('Application')->find($group[0]);
         $links = $application->getLinks();
         $linkHash = array();
         foreach ($links as $link) {
             if (isset($link['rel']) && isset($link['href'])) {
                 $method = isset($link['method']) ? strtolower($link['method']) : '';
                 $method = 'post' !== $method ? 'get' : 'post';
                 $linkHash[$link['rel']] = array('href' => $link['href'], 'method' => $method);
             }
         }
         $queues = Doctrine::getTable('ApplicationLifecycleEventQueue')->getQueuesByApplicationId($group[0], $limitRequestApp);
         foreach ($queues as $queue) {
             if (!isset($linkHash[$queue->getName()])) {
                 $queue->delete();
                 continue;
             }
             $href = $linkHash[$queue->getName()]['href'];
             $method = $linkHash[$queue->getName()]['method'];
             $oauthRequest = OAuthRequest::from_consumer_and_token($consumer, null, $method, $href, $queue->getParams());
             $oauthRequest->sign_request($signatureMethod, $consumer, null);
             $client = new Zend_Http_Client();
             if ('post' !== $method) {
                 $method = 'get';
                 $client->setMethod(Zend_Http_Client::GET);
                 $href .= '?' . $oauthRequest->to_postdata();
             } else {
                 $client->setMethod(Zend_Http_Client::POST);
                 $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, Zend_Http_Client::ENC_URLENCODED);
                 $client->setRawData($oauthRequest->to_postdata());
             }
             $client->setConfig($httpOptions);
             $client->setUri($href);
             $client->setHeaders($oauthRequest->to_header());
             $response = $client->request();
             if ($response->isSuccessful()) {
                 $queue->delete();
             }
             $allRequest++;
             if ($limitRequest && $limitRequest <= $allRequest) {
                 break 2;
             }
         }
         $application->free(true);
         $queues->free(true);
     }
 }
开发者ID:niryuu,项目名称:opOpenSocialPlugin,代码行数:60,代码来源:opOpenSocialExecuteLifecycleEventTask.class.php

示例5: init

 /**
  * @return $this
  * @throws Zend_Http_Client_Exception
  */
 public function init()
 {
     $this->initConfig();
     $this->_http = new Zend_Http_Client();
     $this->_http->setAdapter(new Zend_Http_Client_Adapter_Curl());
     $this->_http->setHeaders(array('Accept' => 'application/' . static::API_RESPONSE_FORMAT, 'Authorization' => 'WSSE profile="UsernameToken"', 'X-WSSE' => $this->_getWsseHeader()));
     return $this;
 }
开发者ID:eltrino,项目名称:DiamanteDeskMagentoExtension,代码行数:12,代码来源:Api.php

示例6: getHttpClient

 public function getHttpClient()
 {
     if ($this->http === null) {
         $this->http = new Zend_Http_Client();
         $this->http->setHeaders('User-Agent', 'vlc-shares/' . X_VlcShares::VERSION . 'X_PageParser_Loader_Http/0.1');
     }
     return $this->http;
 }
开发者ID:google-code-backups,项目名称:vlc-shares,代码行数:8,代码来源:Http.php

示例7: fetchRequest

 public function fetchRequest(RemoteContentRequest $request)
 {
     $outHeaders = array();
     if ($request->hasHeaders()) {
         $headers = explode("\n", $request->getHeaders());
         foreach ($headers as $header) {
             if (strpos($header, ':')) {
                 $key = trim(substr($header, 0, strpos($header, ':')));
                 $val = trim(substr($header, strpos($header, ':') + 1));
                 if (strcmp($key, "User-Agent") != 0 && strcasecmp($key, "Transfer-Encoding") != 0 && strcasecmp($key, "Cache-Control") != 0 && strcasecmp($key, "Expries") != 0 && strcasecmp($key, "Content-Length") != 0) {
                     $outHeaders[$key] = $val;
                 }
             }
         }
     }
     $outHeaders['User-Agent'] = "Shindig PHP";
     $options = array();
     $options['timeout'] = Shindig_Config::get('curl_connection_timeout');
     // configure proxy
     $proxyUrl = Shindig_Config::get('proxy');
     if (!empty($proxyUrl)) {
         $options['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
         $proxy = parse_url($proxyUrl);
         if (isset($proxy['host'])) {
             $options['proxy_host'] = $proxy['host'];
         }
         if (isset($proxy['port'])) {
             $options['proxy_port'] = $proxy['port'];
         }
         if (isset($proxy['user'])) {
             $options['proxy_user'] = $proxy['user'];
         }
         if (isset($proxy['pass'])) {
             $options['proxy_pass'] = $proxy['pass'];
         }
     }
     $client = new Zend_Http_Client();
     $client->setConfig($options);
     $client->setUri($request->getUrl());
     $client->setHeaders($outHeaders);
     if ($request->getContentType()) {
         $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, $request->getContentType());
     }
     if ($request->isPost()) {
         $client->setMethod(Zend_Http_Client::POST);
         $client->setRawData($request->getPostBody());
     } else {
         $client->setMethod(Zend_Http_Client::GET);
     }
     $response = $client->request();
     $request->setHttpCode($response->getStatus());
     $request->setContentType($response->getHeader('Content-Type'));
     $request->setResponseHeaders($response->getHeaders());
     $request->setResponseContent($response->getBody());
     $request->setResponseSize(strlen($response->getBody()));
     return $request;
 }
开发者ID:rysk92,项目名称:opOpenSocialPlugin,代码行数:57,代码来源:opShindigRemoteContentFetcher.class.php

示例8: getHttpClient

 /**
  * Return the singleton instance of the HTTP Client. Note that
  * the instance is reset and cleared of previous parameters and
  * Authorization header values.
  *
  * @return Zend_Http_Client
  */
 public static function getHttpClient()
 {
     if (!isset(self::$httpClient)) {
         self::$httpClient = new Zend_Http_Client();
     } else {
         self::$httpClient->setHeaders('Authorization', null);
         self::$httpClient->resetParameters();
     }
     return self::$httpClient;
 }
开发者ID:brianbui171,项目名称:website_zend_1.11,代码行数:17,代码来源:Oauth.php

示例9: createUser

 function createUser()
 {
     $userURI = $this->APIuri . "/users/" . $this->user;
     $client = new Zend_Http_Client($userURI);
     //$client->setHeaders('Host', $this->requestHost);
     $client->setHeaders('Accept', 'application/json');
     $client->setHeaders('AUTHORIZATION', $this->password);
     $response = $client->request("POST");
     //send the request, using the POST method
     return $response;
 }
开发者ID:shawngraham,项目名称:gap2,代码行数:11,代码来源:EdinaUser.php

示例10: sayRoom

 public function sayRoom($room, $message, $type = 'TextMessage')
 {
     $uri = 'https://' . $this->subdomain . '.campfirenow.com/room/' . $room . '/speak.json';
     $this->client->setUri($uri);
     $params['message']['type'] = $type;
     $params['message']['body'] = $message;
     $this->client->setHeaders('Content-type', 'application/json');
     $this->client->setRawData(json_encode($params));
     $this->client->setMethod(Zend_Http_Client::POST);
     $response = $this->client->request();
     return (bool) ($response->getStatus() == 200);
 }
开发者ID:hhatfield,项目名称:hermes,代码行数:12,代码来源:Bot.php

示例11: postText

 function postText($analysisMethod = 1)
 {
     $client = new Zend_Http_Client(self::APIuri, array('timeout' => 120));
     $client->setHeaders('Accept', 'application/json');
     $client->setHeaders('Content-Type', $this->contentType);
     $client->setHeaders('x-geoNER-alg', $analysisMethod);
     $client->setHeaders('x-geoNER-yahooKey', self::YahooAPIkey);
     //$client->setParameterPost('data', $this->text);
     $client->setRawData($this->text);
     @($response = $client->request("POST"));
     return $response;
 }
开发者ID:shawngraham,项目名称:gap2,代码行数:12,代码来源:SEASR.php

示例12: getClient

 /**
  * @return Zend_Http_Client
  *
  * @throws Zend_Http_Client_Exception
  */
 public function getClient()
 {
     if (!$this->_client) {
         $secretKey = $this->_helper()->getConfigSecretApiKey();
         $this->_client = new Zend_Http_Client();
         $this->_client->setHeaders('clickpag-access-token', $secretKey);
         $this->_client->setHeaders('clickpag-api-version', 'v1');
         $this->_client->setHeaders('Content-Type', 'application/json');
         $this->_client->setHeaders('Accept', 'application/json');
         $this->_client->setMethod(Zend_Http_Client::POST);
     }
     return $this->_client;
 }
开发者ID:marcoescudeiro,项目名称:clickpag-magento,代码行数:18,代码来源:Api.php

示例13: wrapper_getFirstImageFromContent

function wrapper_getFirstImageFromContent($section_id, $exec_droplets = true)
{
    global $database;
    $settings = $database->query(sprintf('SELECT `url` FROM `%smod_wrapper` WHERE section_id = "%d"', CAT_TABLE_PREFIX, $section_id));
    if ($settings->numRows()) {
        $row = $settings->fetchRow();
        ini_set('include_path', CAT_PATH . '/modules/lib_zendlite');
        include 'Zend/Http/Client.php';
        $client = new Zend_Http_Client($row['url'], array('timeout' => '30', 'adapter' => 'Zend_Http_Client_Adapter_Proxy'));
        $client->setCookieJar();
        $client->setHeaders(array('Pragma' => 'no-cache', 'Cache-Control' => 'no-cache', 'Accept-Encoding' => ''));
        try {
            $response = $client->request(Zend_Http_Client::GET);
            if ($response->getStatus() == '200') {
                $content = $response->getBody();
                if ($content != '') {
                    $doc = new DOMDocument();
                    libxml_use_internal_errors(true);
                    // avoid HTML5 errors
                    $doc->loadHTML($content);
                    libxml_clear_errors();
                    $img = $doc->getElementsByTagName('img');
                    return $img->item(0)->getAttribute('src');
                }
            }
        } catch (Zend_HTTP_Client_Adapter_Exception $e) {
        }
        return NULL;
    }
}
开发者ID:ircoco,项目名称:BlackCatCMS,代码行数:30,代码来源:getfirstimage.php

示例14: indexAction

 public function indexAction()
 {
     Zend_Loader::loadClass('Zend_Http_Client');
     $req = $this->getRequest();
     // only decode the url if seems to be encoded
     $url = $req->getParam("url");
     if (stristr($url, "://") === FALSE) {
         $url = base64_decode($url);
     }
     $req_body = $req->getRawBody();
     $client = new Zend_Http_Client($url);
     $headers = array();
     $headers["User-Agent"] = $req->getHeader("User-Agent");
     $headers["Content-Length"] = strlen($req_body);
     if (!is_null($req->getHeader("Content-Type"))) {
         $headers["Content-Type"] = $req->getHeader("Content-Type");
     }
     $client->setHeaders($headers);
     $response = $client->request();
     foreach ($response->getHeaders() as $header => $value) {
         // don't set cookies from the remote host, also
         // transfer and content encodings won't apply to our message
         if (stristr($header, "Set-Cookie") == TRUE || stristr($header, "Transfer-Encoding") == TRUE || stristr($header, "Content-encoding") == TRUE) {
             continue;
         }
         $this->getResponse()->setHeader($header, $value);
     }
     $this->view->content = $response->getBody();
 }
开发者ID:appcelerator,项目名称:entourage,代码行数:29,代码来源:ProxyController.php

示例15: _call

 protected function _call($endpoint, $params = null, $method = 'GET', $data = null)
 {
     if ($params && is_array($params) && count($params) > 0) {
         $args = array();
         foreach ($params as $arg => $val) {
             $args[] = urlencode($arg) . '=' . urlencode($val);
         }
         $endpoint .= '?' . implode('&', $args);
     }
     $url = $this->_getUrl($endpoint);
     $method = strtoupper($method);
     $client = new Zend_Http_Client($url);
     $client->setMethod($method);
     $client->setHeaders(array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
     $client->setAuth(Mage::getStoreConfig('zendesk/general/email') . '/token', Mage::getStoreConfig('zendesk/general/password'));
     if ($method == 'POST') {
         $client->setRawData(json_encode($data), 'application/json');
     }
     Mage::log(print_r(array('url' => $url, 'method' => $method, 'data' => json_encode($data)), true), null, 'zendesk.log');
     $response = $client->request();
     $body = json_decode($response->getBody(), true);
     Mage::log(var_export($body, true), null, 'zendesk.log');
     if ($response->isError()) {
         if (is_array($body) && isset($body['error'])) {
             if (is_array($body['error']) && isset($body['error']['title'])) {
                 throw new Exception($body['error']['title'], $response->getStatus());
             } else {
                 throw new Exception($body['error'], $response->getStatus());
             }
         } else {
             throw new Exception($body, $response->getStatus());
         }
     }
     return $body;
 }
开发者ID:drunkvegas,项目名称:done,代码行数:35,代码来源:Abstract.php


注:本文中的Zend_Http_Client::setHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。