本文整理汇总了PHP中HTTP_Request::addRawQueryString方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::addRawQueryString方法的具体用法?PHP HTTP_Request::addRawQueryString怎么用?PHP HTTP_Request::addRawQueryString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::addRawQueryString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Retrieves a file from cache if it exists, otherwise retreive from net,
* add to cache, and return from cache.
*
* @param string URL to WSDL
* @param array proxy parameters
* @param int expected MD5 of WSDL URL
* @access public
* @return string data
*/
function get($wsdl_fname, $proxy_params = array(), $cache = 0)
{
$cachename = $md5_wsdl = $file_data = '';
if ($this->_cacheUse) {
// Try to retrieve WSDL from cache
$cachename = SOAP_WSDL_Cache::_cacheDir() . '/' . md5($wsdl_fname) . ' .wsdl';
if (file_exists($cachename)) {
$wf = fopen($cachename, 'rb');
if ($wf) {
// Reading cached file
$file_data = fread($wf, filesize($cachename));
$md5_wsdl = md5($file_data);
fclose($wf);
}
if ($cache) {
if ($cache != $md5_wsdl) {
return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname);
}
} else {
$fi = stat($cachename);
$cache_mtime = $fi[8];
//print cache_mtime, time()
if ($cache_mtime + $this->_cacheMaxAge < time()) {
// expired
$md5_wsdl = '';
// refetch
}
}
}
}
if (!$md5_wsdl) {
// Not cached or not using cache. Retrieve WSDL from URL
// is it a local file?
// this section should be replace by curl at some point
if (!preg_match('/^(https?|file):\\/\\//', $wsdl_fname)) {
if (!file_exists($wsdl_fname)) {
return $this->_raiseSoapFault("Unable to read local WSDL {$wsdl_fname}", $wsdl_fname);
}
if (function_exists('file_get_contents')) {
$file_data = file_get_contents($wsdl_fname);
} else {
$file_data = implode('', file($wsdl_fname));
}
} else {
$uri = explode('?', $wsdl_fname);
$rq = new HTTP_Request($uri[0], $proxy_params);
// the user agent HTTP_Request uses fouls things up
if (isset($uri[1])) {
$rq->addRawQueryString($uri[1]);
}
if (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port']) && isset($proxy_params['proxy_user']) && isset($proxy_params['proxy_pass'])) {
$rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'], $proxy_params['proxy_user'], $proxy_params['proxy_pass']);
} elseif (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port'])) {
$rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']);
}
$result = $rq->sendRequest();
if (PEAR::isError($result)) {
return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}," . $rq->getResponseCode(), $wsdl_fname);
}
$file_data = $rq->getResponseBody();
if (!$file_data) {
return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}, no http body", $wsdl_fname);
}
}
$md5_wsdl = md5($file_data);
if ($this->_cacheUse) {
$fp = fopen($cachename, "wb");
fwrite($fp, $file_data);
fclose($fp);
}
}
if ($this->_cacheUse && $cache && $cache != $md5_wsdl) {
return $this->_raiseSoapFault("WSDL Checksum error!", $wsdl_fname);
}
return $file_data;
}
示例2: _select
/**
* Submit REST Request to read data
*
* @param string $method HTTP Method to use: GET, POST,
* @param array $params Array of parameters for the request
* @param bool $returnSolrError If Solr reports a syntax error,
* should we fail outright (false) or
* treat it as an empty result set with
* an error key set (true)?
* @return array|PEAR_Error The Solr response (or a PEAR error)
* @access private
*/
private function _select($method = HTTP_REQUEST_METHOD_GET, $params = array(), $returnSolrError = false)
{
global $timer;
$this->client->setMethod($method);
$this->client->setURL($this->host . "/select/");
$params['wt'] = 'json';
$params['json.nl'] = 'arrarr';
// Build query string for use with GET or POST:
$query = array();
if ($params) {
foreach ($params as $function => $value) {
if ($function != '') {
// Strip custom FacetFields when sharding makes it necessary:
if ($function === 'facet.field') {
$value = $this->_stripUnwantedFacets($value);
// If we stripped all values, skip the parameter:
if (empty($value)) {
continue;
}
}
if (is_array($value)) {
foreach ($value as $additional) {
$additional = urlencode($additional);
$query[] = "{$function}={$additional}";
}
} else {
$value = urlencode($value);
$query[] = "{$function}={$value}";
}
}
}
}
// pass the shard parameter along to Solr if necessary:
if (!empty($this->_solrShards) && is_array($this->_solrShards)) {
$query[] = 'shards=' . urlencode(implode(',', $this->_solrShards));
}
$queryString = implode('&', $query);
if ($this->debug) {
echo "<pre>{$method}: ";
$fullSearchUrl = print_r($this->host . "/select/?" . $queryString, true);
//Add debug parameter so we can see the explain section at the bottom.
$debugSearchUrl = print_r($this->host . "/select/?debugQuery=on&" . $queryString, true);
echo "<a href='" . $debugSearchUrl . "' target='_blank'>{$fullSearchUrl}</a>";
echo "</pre>\n";
}
if ($method == 'GET') {
$this->client->addRawQueryString($queryString);
} elseif ($method == 'POST') {
$this->client->setBody($queryString);
}
// Send Request
$timer->logTime("Prepare to send request to solr");
$result = $this->client->sendRequest();
//$this->client->clearPostData();
$timer->logTime("Send data to solr");
if (!PEAR_Singleton::isError($result)) {
return $this->_process($this->client->getResponseBody(), $returnSolrError);
} else {
return $result;
}
}
示例3: makeRequest
function makeRequest($action, $params)
{
if ($params == '') {
$params = array();
}
$retryCount = 0;
do {
$retry = false;
$timestamp = time();
// Add Actions
$params['Action'] = $action;
$params['Expires'] = gmdate('Y-m-d\\TH:i:s\\Z', $timestamp + 10);
$params['Version'] = '2008-01-01';
$params['AWSAccessKeyId'] = $this->accessKey;
$params['SignatureVersion'] = '1';
// build our string to sign
uksort($params, 'strcasecmp');
$stringToSign = '';
foreach ($params as $key => $val) {
$stringToSign = $stringToSign . "{$key}{$val}";
}
// Sign the string
$hasher =& new Crypt_HMAC($this->secretKey, "sha1");
$params['Signature'] = $this->hex2b64($hasher->hash($stringToSign));
$request = '';
foreach ($params as $key => $val) {
$request .= $key . '=' . urlencode($val) . '&';
}
// get rid of the last &
$request = substr($request, 0, strlen($request) - 1);
// set our endpoint, keeping in mind that not all actions require a queue name in the URI
$endpoint = $this->activeQueueURL;
if ($action == 'ListQueues' || $action == 'CreateQueue') {
$endpoint = $this->endpoint;
}
$req = new HTTP_Request($endpoint);
$req->setMethod('GET');
$req->addRawQueryString($request);
$req->sendRequest();
// check if we should retry this request
$responseCode = $req->getResponseCode();
// you should always retry a 5xx error, as some of these are expected
if ($responseCode >= 500 && $responseCode < 600 && $retryCount <= 5) {
$retry = true;
$retryCount++;
sleep($retryCount / 4 * $retryCount);
}
} while ($retry == true);
$xml = $req->getResponseBody();
// PHP 5 - The easier way!
$data = new SimpleXMLElement($xml);
return $data;
}