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


PHP HttpRequest::getResponseBody方法代码示例

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


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

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

示例2: doPost

 protected function doPost($action, array $data)
 {
     $module = empty($action) ? substr($this->module, 0, -1) : $this->module;
     if (strrpos($action, '.json') === false) {
         $action .= '.json';
     }
     array_walk_recursive($data, 'Lupin_Model_API::encode');
     $url = $this->hostname . $module . $action;
     $request = new HttpRequest($url, HTTP_METH_POST);
     $request->setPostFields($data);
     try {
         $request->send();
     } catch (Exception $e) {
         return false;
     }
     $this->responseCode = $request->getResponseCode();
     if ($request->getResponseCode() !== 200) {
         return false;
     }
     $json = json_decode($request->getResponseBody());
     if (!is_object($json) && !is_array($json)) {
         return false;
     }
     return $json;
 }
开发者ID:jeremykendall,项目名称:spaz-api,代码行数:25,代码来源:API.php

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

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

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

示例6: testGetAsset

 public function testGetAsset()
 {
     $assetID = file_get_contents('test.assetid');
     $sha = sha1(file_get_contents('eyewhite.tga'));
     $r = new HttpRequest($this->server_url . $assetID, HttpRequest::METH_GET);
     $r->send();
     $this->assertEquals(200, $r->getResponseCode());
     $assetData = $r->getResponseBody();
     $this->assertEquals(sha1($assetData), $sha);
 }
开发者ID:QuillLittlefeather,项目名称:mgm-simiangrid,代码行数:10,代码来源:AssetServiceTests.php

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

示例8: getCompetitionsPremierLeague

 /**
  * Permet d'avoir la liste de toutes les comp�titions.
  * (Seul la Premier League est disponible avec un forfait gratuit)
  * @return mixed
  */
 public static function getCompetitionsPremierLeague()
 {
     $reqCometition = 'http://football-api.com/api/?Action=competitions&APIKey=' . self::API_KEY;
     $reponse = new HttpRequest($reqCometition, HttpRequest::METH_GET);
     try {
         $reponse->send();
         if ($reponse->getResponseCode() == 200) {
             return json_decode($reponse->getResponseBody());
         }
     } catch (HttpException $ex) {
         echo $ex;
     }
 }
开发者ID:Jb-Initio,项目名称:Pronos,代码行数:18,代码来源:FootBallAPI.php

示例9: fetchData

 private static function fetchData($station, $time, $lang, $timeSel)
 {
     //temporal public credentials for the NS API.
     $url = "http://" . urlencode("pieter@appsforghent.be") . ":" . urlencode("fEoQropezniTJRw_5oKhGVlFwm_YWdOgozdMjSAVPLk3M3yZYKEa0A") . "@webservices.ns.nl/ns-api-avt?station=" . $station->name;
     $r = new HttpRequest($url, HttpRequest::METH_GET);
     try {
         $r->send();
         if ($r->getResponseCode() == 200) {
             return new SimpleXMLElement($r->getResponseBody());
         }
     } catch (HttpException $ex) {
         throw new Exception("Could not reach NS server", 500);
     }
 }
开发者ID:JeroenDeDauw,项目名称:iRail,代码行数:14,代码来源:liveboard.php

示例10: 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 ( isset($parameters['header']) ) {
        $headers = array();

        foreach ( $parameters['header'] as $header ) {
          list($key, $value) = explode(':', $header, 2);

          $headers[$key] = trim($value);
        }

        $h->setHeaders($headers);
      }

      if ( $parameters['method'] == 'post' ) {
        $h->setBody($parameters['parameters']);
      }

      if ( $parameters['server']['scheme'] === 'https' ) {
        $h->addSslOptions(array('verifypeer' => true,
                                'verifyhost' => true));

        if ( isset($parameters['cafile']) && file_exists($parameters['cafile']) ) {
          $h->addSslOptions(array('cainfo' => $parameters['cafile']));
        }

        if ( isset($parameters['certificate']) ) {
          $h->addSslOptions(array('cert' => $parameters['certificate']));
        }
      }

      $result = '';

      try {
        $h->send();

        $result = $h->getResponseBody();
      } catch ( \Exception $e ) {
        if ( isset($e->innerException) ) {
          trigger_error($e->innerException->getMessage());
        } else {
          trigger_error($e->getMessage());
        }
      }

      return $result;
    }
开发者ID:haraldpdl,项目名称:oscommerce,代码行数:48,代码来源:HttpRequest.php

示例11: query_draw_history

/**
 * Query past cashpot draws by date.
 * @param day a two digit representation of the day eg. 09
 * @param month a three letter representation of the month eg. Jan
 * @param year a two digit representation of the year eg. 99
 * @return the raw html from the page returned by querying a past cashpot draw.
 */
function query_draw_history($day, $month, $year)
{
    $url = "http://www.nlcb.co.tt/search/cpq/cashQuery.php";
    $fields = array('day' => $day, 'month' => $month, 'year' => $year);
    $request = new HttpRequest($url, HttpRequest::METH_POST);
    $request->addPostFields($fields);
    try {
        $request->send();
        if ($request->getResponseCode() == 200) {
            $response = $request->getResponseBody();
        } else {
            throw new Exception("Request for {$url} was unsuccessful. A " . $request->getResponseCode() . " response code was returned.");
        }
    } catch (HttpException $e) {
        echo $e->getMessage();
        throw $e;
    }
    return $response;
}
开发者ID:nireno,项目名称:Cashpot,代码行数:26,代码来源:cashpot.php

示例12: Login

        public function Login()
        {
            $signature = $this->SignMessage("frob", $this->Frob, "perms", "delete");
            $query = "api_key={$this->ApiKey}&perms=delete&frob={$this->Frob}&api_sig={$signature}";
            
            $request = new HttpRequest("http://flickr.com/services/auth/", HTTP_METH_GET);
            $request->setQueryData($query);
            $request->enableCookies();
            
            
            $request->setOptions(array(    "redirect" => 10, 
		                                   "useragent" => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
		                              )
		                        );
            
            $request->send();
            
            var_dump($request->getResponseCode());
            print_r($request->getResponseBody());
            var_dump($request->getResponseStatus());
        }
开发者ID:rchicoria,项目名称:epp-drs,代码行数:21,代码来源:class.Flickr.php

示例13: http_get_file

function http_get_file($url)
{
    $r = new HttpRequest($url, HttpRequest::METH_GET);
    $r->setOptions(array('redirect' => 5));
    try {
        $r->send();
        if ($r->getResponseCode() == 200) {
            $dir = $r->getResponseBody();
        } else {
            echo "Respose code " . $r->getResponseCode() . "({$url})\n";
            echo $r->getResponseBody() . "({$url})\n";
            return "-2";
        }
    } catch (HttpException $ex) {
        echo $ex;
        return "-3";
    }
    $dir = strip_tags($dir);
    return explode("\n", $dir);
    // An array of lines from the url
}
开发者ID:JamesLinus,项目名称:BLFS,代码行数:21,代码来源:blfs-latest.php

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

示例15: CreateBucket

 /**
  * The CreateBucket operation creates a bucket. Not every string is an acceptable bucket name.
  *
  * @param string $bucket_name
  * @return string 
  */
 public function CreateBucket($bucket_name, $region = 'us-east-1')
 {
     $HttpRequest = new HttpRequest();
     $HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
     $timestamp = $this->GetTimestamp(true);
     switch ($region) {
         case "us-east-1":
             $request = "";
             break;
         case "us-west-1":
             $request = "<CreateBucketConfiguration><LocationConstraint>us-west-1</LocationConstraint></CreateBucketConfiguration>";
             break;
         case "eu-west-1":
             $request = "<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>";
             break;
     }
     $data_to_sign = array("PUT", "", "", $timestamp, "/{$bucket_name}/");
     $signature = $this->GetRESTSignature($data_to_sign);
     $HttpRequest->setUrl("https://{$bucket_name}.s3.amazonaws.com/");
     $HttpRequest->setMethod(constant("HTTP_METH_PUT"));
     $headers = array("Content-length" => strlen($request), "Date" => $timestamp, "Authorization" => "AWS {$this->AWSAccessKeyId}:{$signature}");
     $HttpRequest->addHeaders($headers);
     if ($request != '') {
         $HttpRequest->setPutData($request);
     }
     try {
         $HttpRequest->send();
         $info = $HttpRequest->getResponseInfo();
         if ($info['response_code'] == 200) {
             return true;
         } else {
             if ($HttpRequest->getResponseBody()) {
                 $xml = @simplexml_load_string($HttpRequest->getResponseBody());
                 throw new Exception((string) $xml->Message);
             } else {
                 throw new Exception(_("Cannot create S3 bucket at this time. Please try again later."));
             }
         }
     } catch (HttpException $e) {
         throw new Exception($e->__toString());
     }
 }
开发者ID:jasherai,项目名称:libwebta,代码行数:48,代码来源:class.AmazonS3.php


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