setHeaders() public method

This function can be used in several ways to set the client's request headers: 1. By providing two parameters: $name as the header to set (e.g. 'Host') and $value as it's value (e.g. 'www.example.com'). 2. By providing a single header string as the only parameter e.g. 'Host: www.example.com' 3. By providing an array of headers as the first parameter e.g. array('host' => 'www.example.com', 'x-foo: bar'). In This case the function will call itself recursively for each array item.
public setHeaders ( string | array $name, mixed $value = null ) : Zend_Http_Client
$name string | array Header name, full header string ('Header: value') or an array of headers
$value mixed Header value or null
return Zend_Http_Client
コード例 #1
0
ファイル: Client.php プロジェクト: jgermade/magento
 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;
 }
コード例 #2
0
ファイル: Ice.php プロジェクト: rtsantos/mais
 /**
  * 
  */
 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);
 }
コード例 #3
0
ファイル: Ipinfo.php プロジェクト: jsiefer/emarketing
 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;
     }
 }
 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);
     }
 }
コード例 #5
0
 /**
  * @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;
 }
コード例 #6
0
 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;
 }
 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;
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
ファイル: EdinaUser.php プロジェクト: shawngraham/gap2
 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;
 }
コード例 #10
0
ファイル: Bot.php プロジェクト: hhatfield/hermes
 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);
 }
コード例 #11
0
ファイル: SEASR.php プロジェクト: shawngraham/gap2
 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;
 }
コード例 #12
0
 /**
  * @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;
 }
コード例 #13
0
ファイル: getfirstimage.php プロジェクト: ircoco/BlackCatCMS
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;
    }
}
コード例 #14
0
 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();
 }
コード例 #15
0
ファイル: Abstract.php プロジェクト: drunkvegas/done
 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;
 }
コード例 #16
0
 /**
  * @return Zend_Http_Client
  */
 protected function getHttpClient($url = null)
 {
     if ($this->http === null) {
         $this->http = new Zend_Http_Client();
         // maybe it's better to offuscate it
         //$this->http->setHeaders('User-Agent', "vlc-shares/".X_VlcShares::VERSION." hulu/".X_VlcShares_Plugins_Hulu::VERSION);
         $this->http->setHeaders(array('User-Agent' => 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0)', 'Accept' => '*/*'));
         // enable cookies
         $this->http->setCookieJar(true);
         /*
         $this->http->setAdapter("Zend_Http_Client_Adapter_Proxy");
         $this->http->setConfig(array(
         	//'proxy_host' => "141.219.252.132",
         	//'proxy_port' => '3128'
         	
         	//'proxy_host' => '131.179.150.72',
         	//'proxy_port' => '3128',
         	
         	//'proxy_host' => '129.82.12.188',
         	//'proxy_port' => '3128',
         	
         	//'proxy_host' => '130.49.221.40',
         	//'proxy_port' => '3128',
         	
         	'proxy_host' => '65.55.73.222',
         	'proxy_port' => '80'
         
         ));
         */
     }
     if ($url !== null) {
         $this->http->setUri($url);
     }
     return $this->http;
 }
コード例 #17
0
ファイル: Translate.php プロジェクト: sb15/zend-ex-legacy
 public function translate($message, $from, $to)
 {
     $url = "http://ajax.googleapis.com/ajax/services/language/translate";
     $client = new Zend_Http_Client($url, array('maxredirects' => 0, 'timeout' => 30));
     $langpair = $from . '|' . $to;
     $params = array('v' => '1.1', 'q' => $message, 'langpair' => $langpair, 'key' => 'ABQIAAAAMtXAc56OizxVFR_fG__ZZRSrxD5q6_ZpfA55q8xveFjTjZJnShSvPHZq2PGkhSBZ0_OObHUNyy0smw');
     /**
      * Zend_Http_Client
      */
     $client->setParameterPost($params);
     $client->setHeaders('Referer', 'http://sb6.ru');
     $response = $client->request("POST");
     //print_r ($response);
     $data = $response->getBody();
     $serverResult = json_decode($data);
     $status = $serverResult->responseStatus;
     // should be 200
     $result = '';
     if ($status == 200) {
         $result = $serverResult->responseData->translatedText;
     } else {
         echo "retry\n";
         print_r($client->getLastRequest());
         print_r($client->getLastResponse());
         die;
         return $this->translate($message, $from, $to);
     }
     return $result;
 }
コード例 #18
0
 public function responseAction()
 {
     // Get User Configuration
     $epayphId = Mage::getStoreConfig('payment/epayphPaymentModule/epayphId');
     $apiKey = Mage::getStoreConfig('payment/epayphPaymentModule/epayphApiKey');
     $apiSecret = Mage::getStoreConfig('payment/epayphPaymentModule/epayphApiSecret');
     $url = 'https://epay.ph/api/validateIPN';
     $json = json_encode($_POST);
     $client = new Zend_Http_Client($url);
     $client->setHeaders(array('Accept: application/json'));
     $_POST['cmd'] = '_notify-validate';
     $client->setParameterPost($_POST);
     $request = $client->request('POST');
     if ($request->getBody() == '{"return":"VERIFIED"}') {
         $order = Mage::getModel('sales/order');
         $order->loadByIncrementId($_POST['invoice']);
         $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, "Epay.ph Gateway informed us: the payment's Transaction ID is {$_POST['txn_id']}");
         $order->sendNewOrderEmail();
         $order->setEmailSent(true);
         $order->save();
         Mage::getSingleton('checkout/session')->unsQuoteId();
         Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure' => true));
     } else {
         $this->cancelAction(FALSE, 'Epay.ph signature did not validate');
         Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure' => true));
     }
 }
コード例 #19
0
 /**
  * Validate the license information
  *
  * @param string $userId
  * @param array $spMetadata
  * @param array $idpMetadata
  * @return string
  */
 public function validate($userId, array $spMetadata, array $idpMetadata)
 {
     if (!$this->_active) {
         return EngineBlock_LicenseEngine_ValidationManager::LICENSE_UNKNOWN;
     }
     $client = new Zend_Http_Client($this->_url);
     $client->setConfig(array('timeout' => 15));
     try {
         $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json; charset=utf-8')->setParameterGet('userId', urlencode($userId))->setParameterGet('serviceProviderEntityId', urlencode($spMetadata['EntityId']))->setParameterGet('identityProviderEntityId', urlencode($idpMetadata['EntityId']))->request('GET');
         $body = $client->getLastResponse()->getBody();
         $response = json_decode($body, true);
         $status = $response['status'];
     } catch (Exception $exception) {
         $additionalInfo = new EngineBlock_Log_Message_AdditionalInfo($userId, $idpMetadata['EntityId'], $spMetadata['EntityId'], $exception->getTraceAsString());
         EngineBlock_ApplicationSingleton::getLog()->error("Could not connect to License Manager" . $exception->getMessage(), $additionalInfo);
         return EngineBlock_LicenseEngine_ValidationManager::LICENSE_UNKNOWN;
     }
     if ($status['returnUrl']) {
         $currentResponse = EngineBlock_ApplicationSingleton::getInstance()->getHttpResponse();
         $currentResponse->setRedirectUrl($status['returnUrl']);
         $currentResponse->send();
         exit;
     } else {
         if ($status['licenseStatus']) {
             return $status['licenseStatus'];
         } else {
             return EngineBlock_LicenseEngine_ValidationManager::LICENSE_UNKNOWN;
         }
     }
 }
コード例 #20
0
ファイル: CommonHttpTests.php プロジェクト: nbcutech/o3drupal
     /**
      * Test we can set a set of values for one header
      *
      */
     public function testMultipleHeader()
     {
         $this->client->setUri($this->baseuri . 'testHeaders.php');
        $headers = array(
            'Accept-encoding' => 'gzip,deflate',
            'X-baz' => 'Foo',
            'X-powered-by' => array(
                'A large wooden badger',
                'My Shiny Metal Ass',
                'Dark Matter'
            ),
            'Cookie' => array(
                'foo=bar',
                'baz=waka'
            )
        );

        $this->client->setHeaders($headers);
        $res = $this->client->request('TRACE');
        if ($res->getStatus() == 405 || $res->getStatus() == 501) {
            $this->markTestSkipped("Server does not allow the TRACE method");
        }
        $body = strtolower($res->getBody());

        foreach ($headers as $key => $val) {
            if (is_array($val))
                $val = implode(', ', $val);

            $this->assertContains(strtolower("$key: $val"), $body);
        }
     }
コード例 #21
0
 protected function sendRequest($accountId, $accessToken, $body)
 {
     $client = new Zend_Http_Client();
     $client->setUri("https://api.edgecast.com/v2/mcc/customers/{$accountId}/edge/purge");
     $client->setHeaders(array('Authorization' => "TOK:{$accessToken}", 'Content-Type' => 'application/json'));
     $client->setRawData(json_encode($body));
     return $client->request(Zend_Http_Client::PUT);
 }
コード例 #22
0
 /**
  *	Constructor
  *
  *	Connect to the NOC-PS server
  *	@param string $server     IP-address of server (will use default if empty)
  *	@param string $user       Username
  *	@param string $password   Password
  *	@param string $logusername OPTIONAL: client username/id for logging purposes
  */
 function __construct($server = NOCPS_DEFAULT_SERVER, $user = NOCPS_DEFAULT_USERNAME, $password = NOCPS_DEFAULT_PASSWORD, $logusername = '')
 {
     if (!$server) {
         die("Please set the server, username and password in " . __FILE__);
     }
     $http = new Zend_Http_Client();
     $http->setAuth($user, $password);
     /* If the API is used in a website, include IP-address of client as X-forwarded-for header for logging purposes */
     if (isset($_SERVER["REMOTE_ADDR"])) {
         $http->setHeaders("X-Forwarded-For: " . (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] . ", " : "") . $_SERVER['REMOTE_ADDR']);
     }
     if ($logusername) {
         $http->setHeaders("X-Forwarded-For-User: {$logusername}");
     }
     $this->_client = new Zend_XmlRpc_Client("https://{$server}/xmlrpc.php", $http);
     $this->_proxy = $this->_client->getProxy('PXE_API');
 }
コード例 #23
0
ファイル: YouTube.php プロジェクト: hackingman/TubeX
 public function setHttpClient($client, $applicationId = 'MyCompany-MyApp-1.0', $clientId = null, $developerKey = null)
 {
     if ($client === null) {
         $client = new Zend_Http_Client();
     }
     if (!$client instanceof Zend_Http_Client) {
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException('Argument is not an instance of Zend_Http_Client.');
     }
     if ($clientId != null) {
         $client->setHeaders('X-GData-Client', $clientId);
     }
     if ($developerKey != null) {
         $client->setHeaders('X-GData-Key', 'key=' . $developerKey);
     }
     return parent::setHttpClient($client, $applicationId);
 }
コード例 #24
0
 public function setupHttpClient(Zend_Http_Client $httpClient)
 {
     $httpClient->setHeaders('M2M-ApiKey', $this->getApiKey());
     if ($this->_useSession) {
         $user = \App::getUserLogged();
         if (in_array($user->authType, array(App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_REGULAR))) {
             \App::log()->debug("M2M-Session: " . $user->authToken);
             \App::log()->debug("M2M-Organization: " . $user->organizationId);
             $httpClient->setHeaders('M2M-Session', $user->authToken);
             $httpClient->setHeaders('M2M-Organization', $user->organizationId);
         } elseif ($user->authType == App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL) {
             \App::log()->debug("M2M-UGW-Certificate: " . $user->id);
             \App::log()->debug("M2M-Organization: " . $user->organizationId);
             $httpClient->setHeaders('M2M-UGW-Certificate', $user->id);
             $httpClient->setHeaders('M2M-Organization', $user->organizationId);
         }
     }
 }
コード例 #25
0
 /**
  * @return Zend_Http_Client
  */
 public function getClient()
 {
     if ($this->_httpClient === null) {
         $this->_httpClient = new Zend_Http_Client();
         $this->_httpClient->setAdapter($this->_getAdapter());
         $this->_httpClient->setHeaders($this->_getHeaders());
     }
     return $this->_httpClient;
 }
コード例 #26
0
ファイル: Twitter.php プロジェクト: netandreus/zf
 /**
  * Set date header
  *
  * @param  int|string $value
  * @deprecated Not supported by Twitter since April 08, 2009
  * @return void
  */
 protected function _setDate($value)
 {
     if (is_int($value)) {
         $date = date($this->_dateFormat, $value);
     } else {
         $date = date($this->_dateFormat, strtotime($value));
     }
     $this->_localHttpClient->setHeaders('If-Modified-Since', $date);
 }
コード例 #27
0
ファイル: Client.php プロジェクト: beesheer/freehdfootage
 public function saveMetaDataForDocument($id, $data)
 {
     $config = Zend_Registry::getInstance()->config->watson;
     $this->_httpClient->setUri($config->saveMetaDataUrl . $id);
     $this->_httpClient->setHeaders(array('X-SyncTimeout' => $config->timeout, 'Content-Type' => 'application/json', 'Accept' => 'application/json'));
     $response = $this->_httpClient->setRawData($data)->request(Zend_Http_Client::PUT);
     $responseBody = Zend_Json::decode($response->getBody());
     return $responseBody;
 }
コード例 #28
0
 /**
  * Sends a request and returns a response
  *
  * @param CartRecover_Request $request
  * @return Cart_Recover_Response
  */
 public function sendRequest(CartRecover_Request $request)
 {
     $this->client->setUri($request->getUri());
     $this->client->setParameterGet($request->getParams());
     $this->client->setMethod($request->getMethod());
     $this->client->setHeaders('Accept', 'application/json');
     $this->response = $this->client->request();
     if ($this->response->getHeader('Content-Type') != 'application/json') {
         throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
     }
     $body = json_decode($this->response->getBody(), true);
     $response = new CartRecover_Response();
     $response->setRawResponse($this->response->asString());
     $response->setBody($body);
     $response->setHeaders($this->response->getHeaders());
     $response->setStatus($this->response->getMessage(), $this->response->getStatus());
     return $response;
 }
コード例 #29
0
ファイル: Store.php プロジェクト: klaffenboeck/contextus
 public function set($graph, $turtle)
 {
     $client = new Zend_Http_Client();
     $client->setUri($this->_endpoint . $graph);
     $client->setHeaders('Content-Type', 'application/x-turtle');
     $client->setRawData(FourStore_Namespace::to_turtle() . $turtle);
     $response = $client->request('PUT');
     return $response;
 }
コード例 #30
0
ファイル: S3.php プロジェクト: sitengine/sitengine
 public static function getClient(Sitengine_Amazon_S3_Header $header, $body = '')
 {
     require_once 'Zend/Http/Client.php';
     $client = new Zend_Http_Client($header->getUrl());
     $client->setRawData($body);
     foreach ($header->toArray() as $h) {
         $client->setHeaders($h);
     }
     return $client;
 }