本文整理汇总了PHP中Zend_Http_Client::setMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::setMethod方法的具体用法?PHP Zend_Http_Client::setMethod怎么用?PHP Zend_Http_Client::setMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::setMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: getHttpClient
/**
* 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;
}
示例4: __construct
/**
* 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')))));
}
示例5: 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);
}
示例6: dispatch
/**
* 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;
}
示例7: 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;
}
示例8: request
/**
* 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();
}
示例9: process
/**
*
* @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;
}
示例10: executeRequest
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();
}
示例11: login
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) {
}
}
示例12: _httpRequest
/**
* 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;
}
}
示例13: _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;
}
示例14: mailgunRequest
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;
}
}
示例15: getResponse
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();
}