本文整理汇总了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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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
示例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);
}
示例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;
}