setMethod() public method

Validated the passed method and sets it. If we have files set for POST requests, and the new method is not POST, the files are silently dropped.
public setMethod ( string $method = self::GET ) : Zend_Http_Client
$method string
return Zend_Http_Client
 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);
     }
 }
 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;
 }
Ejemplo n.º 3
0
 /**
  * Returns http client object
  *
  * @return \Zend_Http_Client
  */
 public function getHttpClient()
 {
     if (null === $this->_client) {
         $this->_client = new \Zend_Http_Client();
         $headers = array('Accept' => 'application/json', 'X-Postmark-Server-Token' => $this->_apiKey);
         $this->_client->setMethod(\Zend_Http_Client::GET)->setHeaders($headers);
     }
     return $this->_client;
 }
Ejemplo n.º 4
0
 /**
  * the constructor
  *
  * don't use the constructor. use the singleton
  */
 private function __construct($_username, $_password, $_url)
 {
     $this->_url = empty($_url) ? 'https://samurai.sipgate.net/RPC2' : $_url;
     $this->_username = $_username;
     $this->_password = $_password;
     $this->_http = new Zend_Http_Client($this->_url);
     $this->_http->setMethod('post');
     $this->_http->setAuth($_username, $_password);
     $this->_rpc = new Zend_XmlRpc_Client($this->_url, $this->_http->setAuth($_username, $_password));
     $this->_rpc->call('samurai.ClientIdentify', array(0 => new Zend_XmlRpc_Value_Struct(array('ClientName' => new Zend_XmlRpc_Value_String('Tine 2.0 Sipgate'), 'ClientVersion' => new Zend_XmlRpc_Value_String('0.4'), 'ClientVendor' => new Zend_XmlRpc_Value_String('Alexander Stintzing')))));
 }
Ejemplo n.º 5
0
 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);
 }
 /**
  * Proxy, der zB für cross-domain ajax requests verwendet werden kann
  *
  * @param string|array $hosts Erlaubte Hostnamen (RegExp erlaubt, ^ vorne und $ hinten werden autom. angefügt)
  */
 public static function dispatch($hostnames)
 {
     if (Kwf_Setup::getRequestPath() === false) {
         return;
     }
     if (!preg_match('#^/kwf/proxy/?$#i', Kwf_Setup::getRequestPath())) {
         return;
     }
     if (is_string($hostnames)) {
         $hostnames = array($hostnames);
     }
     $proxyUrl = $_REQUEST['proxyUrl'];
     $proxyPostVars = $_POST;
     $proxyGetVars = $_GET;
     if (array_key_exists('proxyUrl', $proxyPostVars)) {
         unset($proxyPostVars['proxyUrl']);
     }
     if (array_key_exists('proxyUrl', $proxyGetVars)) {
         unset($proxyGetVars['proxyUrl']);
     }
     // host checking
     $proxyHost = parse_url($proxyUrl, PHP_URL_HOST);
     $matched = false;
     foreach ($hostnames as $hostname) {
         if (preg_match('/^' . $hostname . '$/i', $proxyHost)) {
             $matched = true;
             break;
         }
     }
     if (!$matched) {
         return;
     }
     // proxying
     $http = new Zend_Http_Client($proxyUrl);
     if (count($_POST)) {
         $http->setMethod(Zend_Http_Client::POST);
     } else {
         $http->setMethod(Zend_Http_Client::GET);
     }
     if (count($_GET)) {
         $http->setParameterGet($proxyGetVars);
     }
     if (count($_POST)) {
         $http->setParameterPost($proxyPostVars);
     }
     $response = $http->request();
     $headers = $response->getHeaders();
     if ($headers && !empty($headers['Content-type'])) {
         header("Content-Type: " . $headers['Content-type']);
     }
     echo $response->getBody();
     exit;
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
 /**
  * Execute CheddarGetter API request
  *
  * @param string $url Url to the API action
  * @param string $username Username
  * @param string $password Password
  * @param array|null $args HTTP post key value pairs
  * @return string Body of the response from the CheddarGetter API
  * @throws Zend_Http_Client_Exception A Zend_Http_Client_Exception may
  * be thrown under a number of conditions but most likely if the tcp socket
  * fails to connect.
  */
 public function request($url, $username, $password, array $args = null)
 {
     // reset
     $this->_client->setUri($url);
     $this->_client->resetParameters();
     $this->_client->setMethod(Zend_Http_Client::GET);
     $this->_client->setAuth($username, $password);
     if ($args) {
         $this->_client->setMethod(Zend_Http_Client::POST);
         $this->_client->setParameterPost($args);
     }
     $response = $this->_client->request();
     return $response->getBody();
 }
Ejemplo n.º 9
0
 /**
  * 
  * @throws Exception
  * @return Varien_Object
  */
 public function process()
 {
     $cacheId = $this->_getCacheKey();
     $response = $cacheId ? Mage::app()->loadCache($cacheId) : false;
     if ($response) {
         $response = unserialize($response);
     }
     if (!$response instanceof Varien_Object) {
         $client = new Zend_Http_Client(self::API_URI, $this->_clientConfig);
         $client->setMethod(Zend_Http_Client::POST);
         $client->setParameterPost($this->getParams());
         $result = $client->request();
         $data = Zend_Json::decode($result->getBody());
         if ($data['status'] != 201) {
             throw new Exception("Premailer failed to run: {$data['message']} #{$data['status']}");
         }
         $htmlClient = new Zend_Http_Client($data['documents']['html'], $this->_clientConfig);
         $textClient = new Zend_Http_Client($data['documents']['txt'], $this->_clientConfig);
         $response = new Varien_Object();
         $response->setVersion($data['version']);
         $response->setHtml($htmlClient->request()->getBody());
         $response->setText($textClient->request()->getBody());
         if ($cacheId) {
             $data = Mage::app()->saveCache(serialize($response), $cacheId, array(self::CACHE_KEY), 60 * 60);
         }
     }
     return $response;
 }
 public function executeRequest(TingClientHttpRequest $request)
 {
     //Transfer request configuration to Zend Client
     $method = $request->getMethod();
     $class = new ReflectionClass(get_class($this->client));
     $this->client->setMethod($class->getConstant($method));
     $this->client->setUri($request->getBaseUrl());
     $this->client->setParameterGet($request->getParameters(TingClientHttpRequest::GET));
     $this->client->setParameterPost($request->getParameters(TingClientHttpRequest::POST));
     //Check for errors
     $response = $this->client->request();
     if ($response->isError()) {
         throw new TingClientException('Unable to excecute Zend Framework HTTP request: ' . $response->getMessage(), $response->getStatus());
     }
     return $response->getBody();
 }
Ejemplo n.º 11
0
 static function login($request)
 {
     $forumPath = SJB_Settings::getSettingByName('forum_path');
     if (empty($forumPath)) {
         return;
     }
     $username = $request['username'];
     $password = $request['password'];
     $url = SJB_System::getSystemSettings('SITE_URL') . $forumPath . '/ucp.php?mode=login';
     $client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent()));
     $client->setCookie($_COOKIE);
     $client->setMethod(Zend_Http_Client::POST);
     $client->setParameterPost(array('username' => $username, 'password' => $password, 'login' => 'Login', 'autologin' => '', 'viewonline' => ''));
     $client->setCookieJar();
     try {
         $ret = $client->request();
         foreach ($ret->getHeaders() as $key => $header) {
             if ('set-cookie' == strtolower($key)) {
                 if (is_array($header)) {
                     foreach ($header as $val) {
                         header("Set-Cookie: " . $val, false);
                     }
                 } else {
                     header("Set-Cookie: " . $header, false);
                 }
             }
         }
     } catch (Exception $ex) {
     }
 }
Ejemplo n.º 12
0
 /**
  * Performs HTTP request to given $url using given HTTP $method.
  * Send additinal query specified by variable/value array,
  * On success returns HTTP response without headers, false on failure.
  *
  * @param string $url OpenID server url
  * @param string $method HTTP request method 'GET' or 'POST'
  * @param array $params additional qwery parameters to be passed with
  * @param int &$staus HTTP status code
  *  request
  * @return mixed
  */
 protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null)
 {
     $client = $this->_httpClient;
     if ($client === null) {
         $client = new Zend_Http_Client($url, array('maxredirects' => 4, 'timeout' => 15, 'useragent' => 'Zend_OpenId'));
     } else {
         $client->setUri($url);
     }
     $client->resetParameters();
     if ($method == 'POST') {
         $client->setMethod(Zend_Http_Client::POST);
         $client->setParameterPost($params);
     } else {
         $client->setMethod(Zend_Http_Client::GET);
         $client->setParameterGet($params);
     }
     try {
         $response = $client->request();
     } catch (Exception $e) {
         $this->_setError('HTTP Request failed: ' . $e->getMessage());
         return false;
     }
     $status = $response->getStatus();
     $body = $response->getBody();
     if ($status == 200 || $status == 400 && !empty($body)) {
         return $body;
     } else {
         $this->_setError('Bad HTTP response');
         return false;
     }
 }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
0
 public function mailgunRequest($type, $domain, $apiKey, $data, $method = Zend_Http_Client::GET, $uriOveride = false)
 {
     $client = new Zend_Http_Client();
     $client->setAuth("api", $apiKey);
     $client->setMethod($method);
     if ($uriOveride) {
         $client->setUri($uriOveride);
     } else {
         $client->setUri($this->apiUrl . $domain . "/" . $type);
     }
     if ($method == Zend_Http_Client::POST) {
         foreach ($data as $key => $value) {
             $client->setParameterPost($key, $value);
         }
     } else {
         foreach ($data as $key => $value) {
             $client->setParameterGet($key, $value);
         }
     }
     try {
         $response = $client->request();
         if ($response->getStatus() == 200) {
             return json_decode($response->getBody());
         } else {
             throw new Zend_Http_Exception("Error connecting to MailGun API. Returned error code: " . $response->getStatus() . " --- " . $response->getBody());
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
 }
Ejemplo n.º 15
0
 public function getResponse()
 {
     $client = new Zend_Http_Client($this->_uri);
     $client->setMethod(Zend_Http_Client::POST);
     $client->setParameterPost(array('apiKey' => $this->getApiKey(), 'token' => $this->getToken()));
     return $client->request();
 }
Ejemplo n.º 16
0
 public static function login($request)
 {
     $blogPath = SJB_Settings::getSettingByName('blog_path');
     if (empty($blogPath)) {
         return;
     }
     $username = $request['username'];
     $password = $request['password'];
     $userInfo = SJB_UserManager::getUserInfoByUserName($username);
     $userInfo = $userInfo ? base64_encode(serialize($userInfo)) : false;
     $url = SJB_System::getSystemSettings('SITE_URL') . $blogPath . '/wp-login.php';
     $client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent(), 'maxredirects' => 0));
     $client->setCookieJar();
     $client->setCookie($_COOKIE);
     $client->setMethod(Zend_Http_Client::POST);
     $client->setParameterPost(array('log' => $username, 'pwd' => $password, 'noSJB' => 1, 'userInfo' => $userInfo, 'wp-submit' => 'Log in'));
     try {
         $response = $client->request();
         foreach ($response->getHeaders() as $key => $header) {
             if ('set-cookie' == strtolower($key)) {
                 if (is_array($header)) {
                     foreach ($header as $val) {
                         header("Set-Cookie: " . $val, false);
                     }
                 } else {
                     header("Set-Cookie: " . $header, false);
                 }
             }
         }
         $_SESSION['wp_cookie_jar'] = @serialize($client->getCookieJar());
     } catch (Exception $ex) {
     }
 }
Ejemplo n.º 17
0
 public function publishUpdate($topicUrls)
 {
     if (!isset($topicUrls)) {
         throw new Kwf_Exception('Please specify a topic url');
     }
     if (!is_array($topicUrls)) {
         $topicUrls = array($topicUrls);
     }
     $client = new Zend_Http_Client($this->_hubUrl);
     $client->setConfig(array('timeout' => 60, 'persistent' => true));
     $client->setMethod(Zend_Http_Client::POST);
     $data = array('hub.mode' => 'publish');
     $client->setParameterPost($data);
     foreach ($topicUrls as $u) {
         if (!preg_match("|^https?://|i", $u)) {
             throw new Kwf_Exception('The specified topic url does not appear to be valid: ' . $topicUrl);
         }
         $client->setParameterPost('hub.url', $u);
     }
     $response = $client->request();
     if ($response->isError()) {
         throw new Kwf_Exception("publishUpdate failed, response status '{$response->getStatus()}' '{$response->getBody()}'");
     }
     return $response;
 }
Ejemplo n.º 18
0
 public function viewemailidsAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $member_ids = array(1, 2, 3, 4, 5);
     $httpClient = new Zend_Http_Client('http://' . CORE_SERVER . '/student/fetchemailids');
     //$httpClient->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
     $httpClient->setMethod('POST');
     $call_back = 'viewbatchinfo';
     $httpClient->setParameterPost(array('member_ids' => $member_ids, 'format' => 'json', 'call_back' => $call_back));
     $response = $httpClient->request();
     if ($response->isError()) {
         $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getHeader('Message') . $response->getBody();
         throw new Zend_Exception($remoteErr, Zend_Log::ERR);
     } else {
         $jsonContent = $response->getBody($response);
         Zend_Registry::get('logger')->debug($jsonContent);
         Zend_Registry::get('logger')->debug(Zend_Json_Decoder::decode($jsonContent));
         Zend_Registry::get('logger')->debug(json_decode($jsonContent));
         /*Zend_Registry::get('logger')->debug(
           Zend_Json_Decoder::decode($jsonContent));*/
         /*$r = Zend_Json_Decoder::decode($jsonContent);
           $batch_info = $r['batch_info'];
           Zend_Registry::get('logger')->debug($batch_info);*/
     }
 }
Ejemplo n.º 19
0
 /**
  * Send a POST request to the specified URL with the specified payload.
  * @param string $url
  * @param string $data
  * @return string Remote data
  **/
 public function sendPOST($url, $data = array())
 {
     $data['_fake_status'] = '200';
     // Zend makes it easier than the others...
     $this->instance->setConfig(array('useragent' => sprintf(Imgur::$user_agent, Imgur::$key)));
     $this->instance->setMethod(Zend_Http_Client::POST);
     $this->instance->setUri($url);
     $this->instance->setParameterPost($data);
     try {
         /** @var Zend_Http_Response */
         $response = $this->instance->request();
         return $response->getBody();
     } catch (Exception $e) {
         throw new Imgur_Exception("Unknown Failure during HTTP Request", null, $e);
     }
 }
Ejemplo n.º 20
0
 /**
  * Perform an API request to Amazon
  *
  * @param string $path
  *    REST path e.g. user/profile
  * @param array $postParams
  *    POST paramaters
  * @return result
  */
 public function request($path, array $postParams = array())
 {
     $sandbox = Mage::getStoreConfig('payment/amazon_payments/sandbox') ? 'sandbox.' : '';
     $client = new Zend_Http_Client();
     $client->setUri("https://api.{$sandbox}amazon.com/{$path}");
     $client->setConfig($this->http_client_config);
     $client->setMethod($postParams ? 'POST' : 'GET');
     foreach ($postParams as $key => $value) {
         $client->setParameterPost($key, $value);
     }
     try {
         $response = $client->request();
     } catch (Zend_Http_Client_Adapter_Exception $e) {
         Mage::logException($e);
         return;
     }
     $data = $response->getBody();
     try {
         $data = Zend_Json::decode($data, true);
     } catch (Exception $e) {
         Mage::logException($e);
     }
     if (empty($data)) {
         return false;
     } else {
         return $data;
     }
 }
Ejemplo n.º 21
0
	/**
	 * Check that we can set methods which are not documented in the RFC. 
	 * Also, check that an exception is thrown if non-word characters are
	 * used in the request method.
	 *
	 */
	public function testSettingExtendedMethod()
	{
		$goodMethods = array(
			'OPTIONS',
			'POST',
			'DOSOMETHING',
			'PROPFIND',
			'Some_Characters'
		);
		
		foreach ($goodMethods as $method) {
			try {
				$this->client->setMethod($method);
			} catch (Exception $e) {
				$this->fail("An unexpected exception was thrown when setting request method to '{$method}'");
			}
		}
		
		$badMethods = array(
			'N@5TYM3T#0D',
			'TWO WORDS',
			'GET http://foo.com/?',
			"Injected\nnewline"
		);
		
		foreach ($badMethods as $method) {
			try {
				$this->client->setMethod($method);
				$this->fail("A Zend_Http_Client_Exception was expected but was not thrown when setting request method to '{$method}'");
			} catch (Zend_Http_Client_Exception $e) {
				// We're ok!
			}
		}
	}
Ejemplo n.º 22
0
 /**
  * Gibt die Geokoordinaten anhand einer Adresse zurück
  *
  * @param string $address Die Adresse die geocodet werden woll
  * @return array|null $geocode Ein Array mit key 'lat' und 'lng'
  */
 public static function getCoordinates($address)
 {
     $q = $address;
     $q = str_replace(array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß'), array('ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss'), $q);
     $getParams = array('address' => $q, 'sensor' => 'false');
     $httpClientConfig = array('timeout' => 20, 'persistent' => false);
     $config = Kwf_Registry::get('config');
     if ($config->http && $config->http->proxy && $config->http->proxy->host && $config->http->proxy->port) {
         $httpClientConfig['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
         $httpClientConfig['proxy_host'] = $config->http->proxy->host;
         $httpClientConfig['proxy_port'] = $config->http->proxy->port;
     }
     $client = new Zend_Http_Client("http://maps.googleapis.com/maps/api/geocode/json", $httpClientConfig);
     $client->setMethod(Zend_Http_Client::GET);
     $client->setParameterGet($getParams);
     $body = utf8_encode($client->request()->getBody());
     try {
         $result = Zend_Json::decode($body);
     } catch (Zend_Json_Exception $e) {
         $e = new Kwf_Exception_Other($e);
         $e->logOrThrow();
     }
     if (isset($result['results'][0]['geometry']['location']['lat']) && isset($result['results'][0]['geometry']['location']['lng'])) {
         return array('lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']);
     }
     return null;
 }
Ejemplo n.º 23
0
 /**
  * HTTP client preparation procedures - should be called before every API 
  * call. 
  * 
  * Will clean up the HTTP client parameters, set the request method to POST
  * and add the always-required authentication information
  * 
  * @param  string $method The API method we are about to use
  * @return void
  */
 protected function prepare($method)
 {
     // Reset parameters
     $this->httpClient->resetParameters();
     // Add authentication data
     $this->httpClient->setMethod('POST');
     $this->httpClient->setParameterPost(array('USER' => $this->authInfo->getUser(), 'PWD' => $this->authInfo->getPassword(), 'SIGNATURE' => $this->authInfo->getSignature(), 'VERSION' => '2.3', 'METHOD' => $method));
 }
Ejemplo n.º 24
0
    /**
     * Check that an exception is thrown if non-word characters are used in
     * the request method.
     *
     * @dataProvider invalidMethodProvider
     */
    public function testSettingInvalidMethodThrowsException($method)
    {
        $this->setExpectedException(
            'Zend\Http\Client\Exception\InvalidArgumentException',
            sprintf('\'%s\' is not a valid HTTP request method', $method));

        $this->_client->setMethod($method);
    }
Ejemplo n.º 25
0
 /**
  * @return \Zend_Http_Client
  */
 private function getHttpClient()
 {
     $client = new \Zend_Http_Client();
     $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
     $client->setMethod(\Zend_Http_Client::POST);
     $client->setParameterPost(array('login' => $this->config->getLogin(), 'password' => $this->config->getPassword(), 'companyid' => $this->config->getCompanyId()));
     return $client;
 }
 /**
  * Carga el KML desde sidco
  * @return type
  */
 protected function _loadKml()
 {
     $zfClient = new Zend_Http_Client($this->_kml_path);
     $zfClient->setConfig(array('timeout' => 45));
     $zfClient->setMethod(Zend_Http_Client::GET);
     $kml = json_decode(Zend_Json::fromXml($zfClient->request()->getBody()));
     return $kml;
 }
 public function indexAction()
 {
     $client = new Zend_Http_Client('https://ws.pagseguro.uol.com.br/v2/sessions/');
     $client->setMethod(Zend_Http_Client::POST);
     $client->setParameterGet('email', '*****@*****.**');
     $client->setParameterGet('token', '9F79900A9B454CE6B18613D7224C0621');
     $client->request();
     var_dump($client->getLastResponse()->getBody());
 }
Ejemplo n.º 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;
 }
 /**
  * 
  * @return array
  */
 public function listar()
 {
     $zfClient = new Zend_Http_Client($this->_url[ENVIRONMENT]);
     $zfClient->setConfig(array('timeout' => 45));
     $zfClient->setMethod(Zend_Http_Client::GET);
     $resultado = Zend_Json::decode($zfClient->request()->getBody());
     if ($resultado["correcto"]) {
         return $resultado["data"];
     }
 }
 public function arcgis()
 {
     $zfClient = new Zend_Http_Client("http://www.arcgis.com/sharing/rest/content/items/3762f644adb644b484c8a74c26d125ed/data?f=json");
     $zfClient->setConfig(array('timeout' => 45));
     $zfClient->setMethod(Zend_Http_Client::GET);
     $kml = json_decode($zfClient->request()->getBody());
     echo "<pre>";
     print_r($kml);
     echo "</pre>";
 }