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


PHP HttpRequest::addQueryData方法代码示例

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


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

示例1: call

 /**
  * Makes api request
  *
  * @param   string     $qid     The id of the query.
  * @param   array      $options optional Query options for the request.
  * @param   string     $path    optional Uri path for the request (/user by default)
  * @param   string     $method  optional Http method (GET by default)
  * @return  object     Returns object that is an response data.
  * @throws  CloudynException
  */
 public function call($qid, array $options = array(), $path = '/user', $method = 'GET')
 {
     $options['qid'] = (string) $qid;
     $options['out'] = self::OUT_JSON;
     if (!isset($options['rqid'])) {
         $options['rqid'] = $this->getRequestId();
     }
     if (!isset($options['apiversion'])) {
         $options['apiversion'] = '0.4';
     }
     $this->request = $this->createNewRequest();
     $this->request->setUrl($this->getUrl() . $path);
     $this->request->setMethod(constant('HTTP_METH_' . strtoupper($method)));
     $this->request->setOptions(array('redirect' => 10, 'useragent' => 'Scalr Client (http://scalr.com)'));
     $this->request->addQueryData($options);
     //This line is very necessary or HttpResponce will add stored cookies
     $this->request->resetCookies();
     $this->message = $this->tryCall($this->request);
     $json = $this->message->getBody();
     $json = preg_replace('#^[^\\{\\[]+|[^\\}\\]]+$#', '', trim($json));
     $obj = json_decode($json);
     if (isset($obj->status) && $obj->status != 'ok' && isset($obj->message)) {
         throw new CloudynException('Cloudyn error. ' . $obj->message);
     }
     return $obj;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:36,代码来源:Cloudyn.php

示例2: request

 protected function request($method, $uri, $args)
 {
     $parsedUrl = parse_url($this->ec2Url);
     $uri = "{$parsedUrl['path']}{$uri}";
     $HttpRequest = new HttpRequest();
     $HttpRequest->setOptions(array("useragent" => "Scalr (https://scalr.net)"));
     $args['Version'] = $this->apiVersion;
     $args['SignatureVersion'] = 2;
     $args['SignatureMethod'] = "HmacSHA256";
     $args['Timestamp'] = $this->getTimestamp();
     $args['AWSAccessKeyId'] = $this->accessKeyId;
     ksort($args);
     foreach ($args as $k => $v) {
         $CanonicalizedQueryString .= "&{$k}=" . rawurlencode($v);
     }
     $CanonicalizedQueryString = trim($CanonicalizedQueryString, "&");
     $url = $parsedUrl['port'] ? "{$parsedUrl['host']}:{$parsedUrl['port']}" : "{$parsedUrl['host']}";
     $args['Signature'] = $this->getSignature(array($method, $url, $uri, $CanonicalizedQueryString));
     $HttpRequest->setUrl("{$parsedUrl['scheme']}://{$url}{$uri}");
     $HttpRequest->setMethod(constant("HTTP_METH_{$method}"));
     if ($args) {
         if ($method == 'POST') {
             $HttpRequest->setPostFields($args);
             $HttpRequest->setHeaders(array('Content-Type' => 'application/x-www-form-urlencoded'));
         } else {
             $HttpRequest->addQueryData($args);
         }
     }
     try {
         $HttpRequest->send();
         $data = $HttpRequest->getResponseData();
         if ($HttpRequest->getResponseCode() == 200) {
             $response = simplexml_load_string($data['body']);
             if ($this->responseFormat == 'Object') {
                 $json = @json_encode($response);
                 $response = @json_decode($json);
             }
             if ($response->Errors) {
                 throw new Exception($response->Errors->Error->Message);
             } else {
                 return $response;
             }
         } else {
             $response = @simplexml_load_string($data['body']);
             if ($response) {
                 throw new Exception($response->Error->Message);
             }
             throw new Exception(trim($data['body']));
         }
         $this->LastResponseHeaders = $data['headers'];
     } catch (Exception $e) {
         if ($e->innerException) {
             $message = $e->innerException->getMessage();
         } else {
             $message = $e->getMessage();
         }
         throw new Exception($message);
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:59,代码来源:Query.php

示例3: test

    public function test()
    {
        $route = 'http://localhost/wordpress/augsburg/de/wp-json/extensions/v0/
					modified_content/posts_and_pages';
        $r = new HttpRequest($route, HttpRequest::METH_GET);
        $r->addQueryData(array('since' => '2000-01-01T00:00:00Z'));
        $r->send();
        $this->assertEquals(200, $r->getResponseCode());
        $body = $r->getResponseBody();
    }
开发者ID:sajjadalisiddiqui,项目名称:cms,代码行数:10,代码来源:RestApi_ModifiedContentTest.php

示例4: sendMessage

 function sendMessage($phonenumber, $message)
 {
     global $property;
     $request = new HttpRequest($property['MOVISTAR']['server'], HttpRequest::METH_GET);
     $request->addQueryData(array('shortcode' => $property['MOVISTAR']['shortcode'], 'msisdn' => $property['MOVISTAR']['msisdn'] . $phonenumber, 'telcoid' => $property['MOVISTAR']['telcoid'], 'encoding' => $property['MOVISTAR']['encoding'], 'smspart' => $property['MOVISTAR']['smspart'], 'udh' => $property['MOVISTAR']['udh'], 'body' => array($message), 'systemID' => $property['MOVISTAR']['systemID']));
     try {
         return $request->send();
     } catch (HttpException $httpe) {
         if (isset($httpe->innerException)) {
             echo $httpe->innerException->getMessage();
             exit;
         }
     }
     return null;
 }
开发者ID:necronet,项目名称:SMSEmpresa,代码行数:15,代码来源:MovistarMessageSender.php

示例5: Request

 private function Request($method, $uri, $args)
 {
     $HttpRequest = new HttpRequest();
     $HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
     $timestamp = $this->GetTimestamp();
     $URL = "queue.amazonaws.com";
     if ($this->Region != 'us-east-1') {
         $URL = "{$this->Region}.queue.amazonaws.com";
     }
     //EU URL: eu-west-1.queue.amazonaws.com
     $args['Version'] = self::API_VERSION;
     $args['SignatureVersion'] = 2;
     $args['SignatureMethod'] = "HmacSHA1";
     $args['Expires'] = $timestamp;
     $args['AWSAccessKeyId'] = $this->AWSAccessKeyId;
     ksort($args);
     foreach ($args as $k => $v) {
         $CanonicalizedQueryString .= "&{$k}=" . urlencode($v);
     }
     $CanonicalizedQueryString = trim($CanonicalizedQueryString, "&");
     $args['Signature'] = $this->GetRESTSignature(array($method, $URL, $uri, $CanonicalizedQueryString));
     $HttpRequest->setUrl("https://{$URL}{$uri}");
     $HttpRequest->setMethod(constant("HTTP_METH_{$method}"));
     if ($args) {
         $HttpRequest->addQueryData($args);
     }
     try {
         $HttpRequest->send();
         //$info = $HttpRequest->getResponseInfo();
         $data = $HttpRequest->getResponseData();
         $this->LastResponseHeaders = $data['headers'];
         $response = simplexml_load_string($data['body']);
         if ($response->Error) {
             throw new Exception($response->Error->Message);
         } else {
             return $response;
         }
     } catch (Exception $e) {
         if ($e->innerException) {
             $message = $e->innerException->getMessage();
         } else {
             $message = $e->getMessage();
         }
         throw new Exception($message);
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:46,代码来源:class.AmazonSQS.php

示例6: fetch

 public function fetch($query)
 {
     $request = new HttpRequest($this->getUrl(), HttpRequest::METH_GET);
     $request->addQueryData(array($this->getParamName() => $query));
     if (sfConfig::get('sf_logging_enabled')) {
         sfContext::getInstance()->getLogger()->info(sprintf('Requesting search results for \'%s\'', $query));
     }
     try {
         $request->send();
     } catch (HttpException $e) {
         if (sfConfig::get('sf_logging_enabled')) {
             sfContext::getInstance()->getLogger()->info(sprintf('There is an error with the http request: %s', $e->__toString()));
         }
     }
     $html = $request->getResponseBody();
     $hit = $this->extractHit($html);
     if (sfConfig::get('sf_logging_enabled')) {
         sfContext::getInstance()->getLogger()->info(sprintf('Found %s results for \'%s\'', $hit, $query));
     }
     return $hit;
 }
开发者ID:hoydaa,项目名称:googlevolume.com,代码行数:21,代码来源:AbstractHitFetcher.class.php

示例7: Request

 private function Request($method, $uri, $request_body, $query_args, $headers = array())
 {
     $HttpRequest = new HttpRequest();
     $HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
     $timestamp = $this->GetTimestamp();
     $signature = $this->GetRESTSignature($timestamp);
     $HttpRequest->setUrl("https://cloudfront.amazonaws.com/" . self::API_VERSION . $uri);
     $HttpRequest->setMethod($method);
     if ($query_args) {
         $HttpRequest->addQueryData($query_args);
     }
     if ($request_body) {
         if ($method == constant("HTTP_METH_POST")) {
             $HttpRequest->setRawPostData(trim($request_body));
         } else {
             $HttpRequest->setPutData(trim($request_body));
         }
         $headers["Content-type"] = "text/xml";
     }
     $headers["Date"] = $timestamp;
     $headers["Authorization"] = "AWS {$this->AWSAccessKeyId}:{$signature}";
     $HttpRequest->addHeaders($headers);
     try {
         $HttpRequest->send();
         //$info = $HttpRequest->getResponseInfo();
         $data = $HttpRequest->getResponseData();
         $this->LastResponseHeaders = $data['headers'];
         return $data['body'];
     } catch (Exception $e) {
         if ($e->innerException) {
             $message = $e->innerException->getMessage();
         } else {
             $message = $e->getMessage();
         }
         throw new Exception($message);
     }
 }
开发者ID:jasherai,项目名称:libwebta,代码行数:37,代码来源:class.AmazonCloudFront.php

示例8: ajaxAction

 public function ajaxAction()
 {
     $this->view = new Lupin_View();
     $method = strtolower($this->_request->getParam('method'));
     $query_uri = trim($this->_request->getParam('query_uri'), '/ ');
     $url = $this->_request->getParam('url');
     $extraParams = $this->_request->getParam('param');
     $params = array('format' => $this->_request->getParam('format'));
     if (!empty($extraParams)) {
         foreach ($extraParams as $newParam) {
             $parms = explode('=', $newParam, 2);
             if (count($parms) > 1) {
                 list($key, $value) = $parms;
                 $params[$key] = $value;
             }
         }
     }
     $newMethod = HTTP_METH_GET;
     switch ($method) {
         case 'get':
             $newMethod = HTTP_METH_GET;
             break;
         case 'post':
             $newMethod = HTTP_METH_POST;
             break;
         case 'put':
             $newMethod = HTTP_METH_PUT;
             break;
         case 'delete':
             $newMethod = HTTP_METH_DELETE;
             break;
         case 'head':
             $newMethod = HTTP_METH_HEAD;
             break;
     }
     $email = $this->_request->getParam('email');
     $pass = $this->_request->getParam('secretKey');
     $request_url = 'http://' . $url . '/' . $query_uri;
     $request = new HttpRequest($request_url, $newMethod);
     if ($email && $pass) {
         $encoded_auth = base64_encode($email . ':' . $pass);
         $request->addHeaders(array('Authorization' => 'Basic ' . $encoded_auth));
     }
     if ("post" == $method) {
         $request->addPostFields($params);
     } else {
         $request->addQueryData($params);
     }
     $res = $request->send();
     function collapseHeaders($headers)
     {
         $header_string = "";
         foreach ($headers as $name => $value) {
             $header_string .= $name . ": " . wordwrap($value, 45, "\n\t") . "\n";
         }
         return $header_string;
     }
     $responseInfo = $request->getResponseInfo();
     $response = array('request_url' => $responseInfo['effective_url'], 'response_headers' => collapseHeaders($res->getHeaders()), 'content' => $res->getBody(), 'status' => $res->getResponseCode(), 'method' => strtoupper($method), 'request_post_fields' => http_build_query(!is_null($postFields = $request->getPostFields()) ? $postFields : array()));
     $this->view->renderJson($response);
 }
开发者ID:jeremykendall,项目名称:spaz-api,代码行数:61,代码来源:TesterController.php

示例9: HttpRequest

<html>
    <head></head>
    <body>
        <?php 
$r = new HttpRequest('http://www.webservicex.net/globalweather.asmx/GetWeather', HttpRequest::METH_GET);
//set headers
$arrayHeaders = array("as_q" => "Web Service", "cityName" => "Singapore", "countryName" => "Singapore");
$r->addQueryData($arrayHeaders);
try {
    $r->send();
    echo '<h2>Request Header</h2>';
    echo '<pre>';
    print_r($r->getRawRequestMessage());
    echo '</pre>';
    $responseCode = $r->getResponseCode();
    $responseHeader = $r->getResponseHeader();
    $responseBody = $r->getResponseBody();
    $responseBody = '<?xml version="1.0" encoding="utf-8"?>
<CurrentWeather>
  <Location>Singapore / Changi Airport, Singapore (WSSS) 01-22N 103-59E 16M</Location>
  <Time>Nov 19, 2013 - 02:30 AM EST / 2013.11.19 0730 UTC</Time>
  <Wind> from the N (010 degrees) at 5 MPH (4 KT) (direction variable):0</Wind>
  <Visibility> greater than 7 mile(s):0</Visibility>
  <SkyConditions> partly cloudy</SkyConditions>
  <Temperature> 87 F (31 C)</Temperature>
  <DewPoint> 71 F (22 C)</DewPoint>
  <RelativeHumidity> 58%</RelativeHumidity>
  <Pressure> 29.71 in. Hg (1006 hPa)</Pressure>
  <Status>Success</Status>
</CurrentWeather>';
    //load the XML string in the variable $responseBody to an XML object
开发者ID:jipengxiang,项目名称:phpWebService,代码行数:31,代码来源:Exercise2_1.php

示例10: ajaxAction

 public function ajaxAction()
 {
     $this->view = new Lupin_View();
     $method = strtolower($this->_request->getParam('method'));
     $query_uri = trim($this->_request->getParam('query_uri'), '/ ');
     $url = $this->_request->getParam('url');
     $ssl = $this->_request->getParam('ssl');
     $extraParams = $this->_request->getParam('param');
     $params = array();
     if (!empty($extraParams)) {
         foreach ($extraParams as $newParam) {
             $parms = explode('=', $newParam, 2);
             if (count($parms) > 1) {
                 list($key, $value) = $parms;
                 $params[$key] = $value;
             }
         }
     }
     $newMethod = HTTP_METH_GET;
     switch ($method) {
         case 'get':
             $newMethod = HTTP_METH_GET;
             break;
         case 'post':
             $newMethod = HTTP_METH_POST;
             break;
         case 'put':
             $newMethod = HTTP_METH_PUT;
             break;
         case 'delete':
             $newMethod = HTTP_METH_DELETE;
             break;
         case 'head':
             $newMethod = HTTP_METH_HEAD;
             break;
     }
     $email = $this->_request->getParam('email');
     $pass = $this->_request->getParam('secretKey');
     $request_url = 'http' . ($ssl !== null ? 's' : '') . '://' . $url . '/' . $query_uri;
     $httpOptions = array();
     if ($email && $pass) {
         $httpOptions = array('headers' => array('Accept' => '*/*'), 'httpauth' => $email . ':' . $pass, 'httpauthtype' => HTTP_AUTH_DIGEST);
     }
     $request = new HttpRequest($request_url, $newMethod, $httpOptions);
     if ("post" == $method) {
         $request->addPostFields($params);
     } else {
         $request->addQueryData($params);
     }
     $res = $request->send();
     $responseInfo = $request->getResponseInfo();
     $response = array('request_url' => $responseInfo['effective_url'], 'response_headers' => $this->collapseHeaders($res->getHeaders()), 'content' => $res->getBody(), 'status' => $res->getResponseCode(), 'method' => strtoupper($method), 'request_post_fields' => http_build_query(!is_null($postFields = $request->getPostFields()) ? $postFields : array()));
     $this->view->renderJson($response);
 }
开发者ID:jeremykendall,项目名称:frapi,代码行数:54,代码来源:TesterController.php

示例11: HttpRequest

<?php

echo "dbg2";
$r = new HttpRequest("http://example.com/feed.rss", HttpRequest::METH_GET);
echo "after new HttpRequest";
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
    echo "about to send";
    $r->send();
    echo "sent";
    echo "response:" . $r->getResponseCode();
    if ($r->getResponseCode() == 200) {
        file_put_contents('local.rss', $r->getResponseBody());
        echo $r->getResponseBody();
    }
} catch (HttpException $ex) {
    echo $ex;
}
开发者ID:KevinSheedy,项目名称:kevinsheedy.ie,代码行数:19,代码来源:getStation.php


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