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


PHP HttpRequest::send方法代码示例

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


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

示例1: sendPost

 protected function sendPost($url, array $data = array())
 {
     $this->request->setUrl($this->getUrl($url));
     $this->request->setMethod(\HttpRequest::METH_POST);
     if (count($data)) {
         $this->request->setPostFields($data);
     }
     $this->request->send();
 }
开发者ID:visor,项目名称:nano,代码行数:9,代码来源:HttpTest.php

示例2: testDeleteAsset

 public function testDeleteAsset()
 {
     $assetID = file_get_contents('test.assetid');
     $r = new HttpRequest($this->server_url . $assetID, HttpRequest::METH_DELETE);
     $r->send();
     $this->assertEquals(200, $r->getResponseCode());
 }
开发者ID:QuillLittlefeather,项目名称:mgm-simiangrid,代码行数:7,代码来源:AssetServiceTests.php

示例3: run

 /**
  * Performs the test.
  *
  * @return \Jyxo\Beholder\Result
  */
 public function run()
 {
     // The http extension is required
     if (!extension_loaded('http')) {
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension http missing');
     }
     $http = new \HttpRequest($this->url, \HttpRequest::METH_GET, array('connecttimeout' => 5, 'timeout' => 10, 'useragent' => 'JyxoBeholder'));
     try {
         $http->send();
         if (200 !== $http->getResponseCode()) {
             throw new \Exception(sprintf('Http error: %s', $http->getResponseCode()));
         }
         if (isset($this->tests['body'])) {
             $body = $http->getResponseBody();
             if (!preg_match($this->tests['body'], $body)) {
                 $body = trim(strip_tags($body));
                 throw new \Exception(sprintf('Invalid body: %s', \Jyxo\String::cut($body, 16)));
             }
         }
         // OK
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS);
     } catch (\HttpException $e) {
         $inner = $e;
         while (null !== $inner->innerException) {
             $inner = $inner->innerException;
         }
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $inner->getMessage());
     } catch (\Exception $e) {
         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $e->getMessage());
     }
 }
开发者ID:honzap,项目名称:php,代码行数:36,代码来源:HttpResponse.php

示例4: sendRequest

 /**
  * Send the request
  *
  * This function sends the actual request to the
  * remote/local webserver using pecl http
  *
  * @link http://us2.php.net/manual/en/http.request.options.php
  * @todo catch exceptions from HttpRequest and rethrow
  * @todo handle Puts
  */
 public function sendRequest()
 {
     $options = array('connecttimeout' => $this->requestTimeout);
     // if we have any listeners register an onprogress callback
     if (count($this->_listeners) > 0) {
         $options['onprogress'] = array($this, '_onprogress');
     }
     $tmp = 'HTTP_METH_' . strtoupper($this->verb);
     if (defined($tmp)) {
         $method = constant($tmp);
     } else {
         $method = HTTP_METH_GET;
     }
     $this->request = $request = new \HttpRequest($this->uri->url, $method, $options);
     $request->setHeaders($this->headers);
     if ($this->body) {
         $request->setRawPostData($this->body);
     }
     $request->send();
     $response = $request->getResponseMessage();
     $body = $response->getBody();
     $details = $this->uri->toArray();
     $details['code'] = $request->getResponseCode();
     $details['httpVersion'] = $response->getHttpVersion();
     $headers = new Request\Headers($response->getHeaders());
     $cookies = $request->getResponseCookies();
     return new Request\Response($details, $body, $headers, $cookies);
 }
开发者ID:kingsj,项目名称:core,代码行数:38,代码来源:Http.php

示例5: makeApiRequest

 protected function makeApiRequest($type, $action, $params, $format = null, $creds = null, $useCache = true)
 {
     $config = load_class('Config');
     $url = $config->config['base_url'] . 'api/' . urlencode($type);
     $useCache = false;
     // $creds === false means don't use credentials
     // $creds === null  means use default credentials
     // $creds === array($user, $pass) otherwise (where pass is md5)
     // TODO pull this from config or make default user
     if ($creds === null) {
         // TODO find a better solution here !!!
         if (!array_key_exists('api_creds_user', $config->config)) {
             $config->config['api_creds_user'] = 'kevin';
         }
         if (!array_key_exists('api_creds_token', $config->config)) {
             $config->config['api_creds_token'] = '6228bd57c9a858eb305e0fd0694890f7';
         }
         $creds = array($config->config['api_creds_user'], $config->config['api_creds_token']);
     }
     $req = new StdClass();
     $req->request = new StdClass();
     if (is_array($creds)) {
         $req->request->auth = new StdClass();
         $req->request->auth->user = $creds[0];
         $req->request->auth->pass = $creds[1];
     }
     $req->request->action->type = $action;
     if (is_array($params)) {
         $req->request->action->data = new StdClass();
         foreach ($params as $k => $v) {
             $req->request->action->data->{$k} = $v;
         }
     }
     $payload = $this->encode_request($req, $format);
     $cache_filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'joindin-test-' . md5($url . $payload);
     if ($useCache) {
         // Check for reading from cache
         if (file_exists($cache_filename) && is_readable($cache_filename)) {
             $cache_data = json_decode(file_get_contents($cache_filename));
             if (time() < $cache_data->expires) {
                 return $cache_data->payload;
             }
         }
     }
     $request = new HttpRequest($url, HttpRequest::METH_POST);
     $request->setBody($payload);
     if ($format == 'xml') {
         $request->setHeaders(array('Content-Type' => 'text/xml'));
     } else {
         // json is the default
         $request->setHeaders(array('Content-Type' => 'application/json'));
     }
     $response = $request->send();
     if ($useCache) {
         $cache_data = json_encode(array('payload' => $response->getBody(), 'expires' => time() + 3600));
         file_put_contents($cache_filename, $cache_data);
         // chmod( $cache_filename, 0777 );
     }
     return $response->getBody();
 }
开发者ID:jaytaph,项目名称:joind.in,代码行数:60,代码来源:ApiTestBase.php

示例6: send

 /**
  * Send this HTTP request
  *
  * @throws Horde_Http_Exception
  * @return Horde_Http_Response_Base
  */
 public function send()
 {
     if (!defined('HTTP_METH_' . $this->method)) {
         throw new Horde_Http_Exception('Method ' . $this->method . ' not supported.');
     }
     $httpRequest = new HttpRequest((string) $this->uri, constant('HTTP_METH_' . $this->method));
     $data = $this->data;
     if (is_array($data)) {
         $httpRequest->setPostFields($data);
     } else {
         if ($this->method == 'PUT') {
             $httpRequest->setPutData($data);
         } else {
             $httpRequest->setBody($data);
         }
     }
     $httpRequest->setOptions($this->_httpOptions());
     try {
         $httpResponse = $httpRequest->send();
     } catch (HttpException $e) {
         if (isset($e->innerException)) {
             throw new Horde_Http_Exception($e->innerException);
         } else {
             throw new Horde_Http_Exception($e);
         }
     }
     return new Horde_Http_Response_Peclhttp((string) $this->uri, $httpResponse);
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:34,代码来源:Peclhttp.php

示例7: request

 protected function request($path, $args = array(), $files = array(), $envId = 0, $version = 'v1')
 {
     try {
         $httpRequest = new HttpRequest();
         $httpRequest->setMethod(HTTP_METH_POST);
         $postData = json_encode($args);
         $stringToSign = "/{$version}{$path}:" . $this->API_ACCESS_KEY . ":{$envId}:{$postData}:" . $this->API_SECRET_KEY;
         $validToken = Scalr_Util_CryptoTool::hash($stringToSign);
         $httpRequest->setHeaders(array("X_SCALR_AUTH_KEY" => $this->API_ACCESS_KEY, "X_SCALR_AUTH_TOKEN" => $validToken, "X_SCALR_ENV_ID" => $envId));
         $httpRequest->setUrl("http://scalr-trunk.localhost/{$version}{$path}");
         $httpRequest->setPostFields(array('rawPostData' => $postData));
         foreach ($files as $name => $file) {
             $httpRequest->addPostFile($name, $file);
         }
         $httpRequest->send();
         if ($this->debug) {
             print "<pre>";
             var_dump($httpRequest->getRequestMessage());
             var_dump($httpRequest->getResponseCode());
             var_dump($httpRequest->getResponseData());
         }
         $data = $httpRequest->getResponseData();
         return @json_decode($data['body']);
     } catch (Exception $e) {
         echo "<pre>";
         if ($this->debug) {
             var_dump($e);
         } else {
             var_dump($e->getMessage());
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:32,代码来源:api.php

示例8: 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

示例9: __call

 /**
  * RPC method proxy
  *
  * @param string $method RPC method name
  * @param array $params RPC method arguments
  * @return mixed decoded RPC response
  * @throws Exception
  */
 public function __call($method, array $params)
 {
     if (strlen($this->__namespace)) {
         $method = $this->__namespace . '.' . $method;
     }
     $this->__request->setContentType("text/xml");
     $this->__request->setRawPostData(xmlrpc_encode_request($method, $params, array("encoding" => $this->__encoding) + (array) $this->__options));
     $response = $this->__request->send();
     if ($response->getResponseCode() != 200) {
         throw new Exception($response->getResponseStatus(), $response->getResponseCode());
     }
     $data = xmlrpc_decode($response->getBody(), $this->__encoding);
     if (xmlrpc_is_fault($data)) {
         throw new Exception((string) $data['faultString'], (int) $data['faultCode']);
     }
     return $data;
 }
开发者ID:garybulin,项目名称:php7,代码行数:25,代码来源:XmlRpcClient.php

示例10: cb_get_pois

function cb_get_pois($params)
{
    $base_addr = 'http://orion.lab.fi-ware.org:1026/v1/queryContext';
    $limit = 1000;
    try {
        $orion_key = json_decode(file_get_contents('../orion_key.txt'))[0];
    } catch (Exception $ex) {
        $orion_key = "";
    }
    $search_area = cb_search_area($params);
    $ans = array();
    $next = 0;
    $more = TRUE;
    try {
        while ($more) {
            $more = FALSE;
            $addr = $base_addr . '?';
            if ($next > 0) {
                $addr = $addr . 'offset=' . $next . '&';
            }
            $addr = $addr . 'limit=' . $limit;
            $next = $next + $limit;
            $http = new HttpRequest($addr, HTTP_METH_POST);
            $headers = array();
            $headers['Content-Type'] = 'application/json';
            $headers['Accept'] = 'application/json';
            if ($orion_key != "") {
                $headers['X-Auth-Token'] = $orion_key;
            }
            $http->setHeaders($headers);
            $body = '{"entities":[{"type":"cie_poi","isPattern":"true","id":"cie_poi_*' . '"}],"attributes":["data"],"restriction":{"scopes":[{"type":"FI' . 'WARE::Location","value":' . $search_area . '}]}}';
            $http->setBody($body);
            $respmsg = $http->send();
            $resp_str = $respmsg->getBody();
            $resp = json_decode($resp_str);
            if (property_exists($resp, 'contextResponses')) {
                $context_responses = $resp->contextResponses;
                foreach ($context_responses as $context_response) {
                    $more = TRUE;
                    $context_element = $context_response->contextElement;
                    $id = $context_element->id;
                    $uuid = substr($id, 8);
                    $attributes = $context_element->attributes;
                    foreach ($attributes as $attribute) {
                        $name = $attribute->name;
                        if ($name == 'data') {
                            $encoded_value = $attribute->value;
                            $json_value = rawurldecode($encoded_value);
                            $ans[$uuid] = json_decode($json_value, TRUE);
                        }
                    }
                }
            }
        }
    } catch (Exception $e) {
    }
    return $ans;
}
开发者ID:Fiware,项目名称:webui.POIDataProvider,代码行数:58,代码来源:cb.php

示例11: execute

 public static function execute($parameters)
 {
     $h = new \HttpRequest($parameters['server']['scheme'] . '://' . $parameters['server']['host'] . $parameters['server']['path'] . (isset($parameters['server']['query']) ? '?' . $parameters['server']['query'] : ''), static::$_methods[$parameters['method']], array('redirect' => 5));
     if ($parameters['method'] == 'post') {
         $h->setRawPostData($parameters['parameters']);
     }
     $h->send();
     return $h->getResponseBody();
 }
开发者ID:kdexter,项目名称:oscommerce,代码行数:9,代码来源:HttpRequest.php

示例12: httpRequestSoapData

/**
 * 2012年6月28日 携程 唐春龙 研发中心
 * 通过httpRequest调用远程webservice服务(返回一个XML)
 * @param $responseUrl 远程服务的地址
 * @param $requestXML 远程服务的参数请求体XML
 * @param 返回XML
 */
function httpRequestSoapData($responseUrl, $requestXML)
{
    try {
        $myhttp = new HttpRequest($responseUrl . "?WSDL", "POST");
        //--相对于API2.0固定
        $r_head = <<<BEGIN
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Request xmlns="http://ctrip.com/">
<requestXML>
BEGIN;
        //--相对于API2.0固定
        $r_end = <<<BEGIN
</requestXML>
</Request>
</soap:Body>
</soap:Envelope>
BEGIN;
        //返回头--相对于API2.0固定
        $responseHead = <<<begin
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RequestResponse xmlns="http://ctrip.com/"><RequestResult>
begin;
        //返回尾--相对于API2.0固定
        $responseEnd = <<<begin
</RequestResult></RequestResponse></soap:Body></soap:Envelope>
begin;
        $requestXML = str_replace("<", @"&lt;", $requestXML);
        $requestXML = str_replace(">", @"&gt;", $requestXML);
        $requestXML = $r_head . $requestXML . $r_end;
        //echo "<!--" . $requestXML ."-->";
        $myhttp->open();
        $myhttp->send($requestXML);
        $responseBodys = $myhttp->getResponseBody();
        //这里有可能有HEAD,要判断一下
        if (strpos($responseBodys, "Content-Type: text/xml; charset=utf-8")) {
            $coutw = $myhttp->responseBodyWithoutHeader;
        } else {
            $coutw = $responseBodys;
        }
        //$myhttp->responseBodyWithoutHeader;
        //$coutw=$myhttp->responseBodyWithoutHeader;
        $coutw = str_replace($responseHead, "", $coutw);
        //替换返回头
        $coutw = str_replace($responseEnd, "", $coutw);
        //替换返回尾
        $coutw = str_replace("&lt;", "<", $coutw);
        //将符号换回来
        $coutw = str_replace("&gt;", ">", $coutw);
        //将符号换回来
        // echo $coutw;
        return $coutw;
    } catch (SoapFault $fault) {
        return $fault->faultcode;
    }
}
开发者ID:Yougmark,项目名称:TiCheck_Server,代码行数:63,代码来源:httpRequestData.php

示例13: 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

示例14: returnWord

function returnWord()
{
    $r = new HttpRequest('http://randomword.setgetgo.com/get.php?len=6', "GET");
    $r->send();
    if ($r->getStatus() == 200) {
        return $_SESSION["word"] = $r->getResponseBody();
    } else {
        return "cannot generate music";
    }
}
开发者ID:NikiHrs,项目名称:form-php-homework,代码行数:10,代码来源:metods.php

示例15: OnStartForking

 public function OnStartForking()
 {
     $db = \Scalr::getDb();
     // Get pid of running daemon
     $pid = @file_get_contents(CACHEPATH . "/" . __CLASS__ . ".Daemon.pid");
     $this->Logger->info("Current daemon process PID: {$pid}");
     // Check is daemon already running or not
     if ($pid) {
         $Shell = new Scalr_System_Shell();
         // Set terminal width
         putenv("COLUMNS=400");
         // Execute command
         $ps = $Shell->queryRaw("ps ax -o pid,ppid,command | grep ' 1' | grep {$pid} | grep -v 'ps x' | grep DBQueueEvent");
         $this->Logger->info("Shell->queryRaw(): {$ps}");
         if ($ps) {
             // daemon already running
             $this->Logger->info("Daemon running. All ok!");
             return true;
         }
     }
     $rows = $db->Execute("SELECT history_id FROM webhook_history WHERE status='0'");
     while ($row = $rows->FetchRow()) {
         $history = WebhookHistory::findPk(bin2hex($row['history_id']));
         if (!$history) {
             continue;
         }
         $endpoint = WebhookEndpoint::findPk($history->endpointId);
         $request = new HttpRequest();
         $request->setMethod(HTTP_METH_POST);
         if ($endpoint->url == 'SCALR_MAIL_SERVICE') {
             $request->setUrl('https://my.scalr.com/webhook_mail.php');
         } else {
             $request->setUrl($endpoint->url);
         }
         $request->setOptions(array('timeout' => 3, 'connecttimeout' => 3));
         $dt = new DateTime('now', new DateTimeZone("UTC"));
         $timestamp = $dt->format("D, d M Y H:i:s e");
         $canonical_string = $history->payload . $timestamp;
         $signature = hash_hmac('SHA1', $canonical_string, $endpoint->securityKey);
         $request->addHeaders(array('Date' => $timestamp, 'X-Signature' => $signature, 'X-Scalr-Webhook-Id' => $history->historyId, 'Content-type' => 'application/json'));
         $request->setBody($history->payload);
         try {
             $request->send();
             $history->responseCode = $request->getResponseCode();
             if ($request->getResponseCode() <= 205) {
                 $history->status = WebhookHistory::STATUS_COMPLETE;
             } else {
                 $history->status = WebhookHistory::STATUS_FAILED;
             }
         } catch (Exception $e) {
             $history->status = WebhookHistory::STATUS_FAILED;
         }
         $history->save();
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:55,代码来源:class.DBQueueEventProcess.php


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