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


PHP HttpRequest::execute方法代码示例

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


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

示例1: executeCall

 /**
  * Execute a HTTP request to MusicBrainz server, errorMessage attribute is set in case of error.
  *
  * @return bool|string MusicBrainz informations or false on failure
  */
 private function executeCall()
 {
     //request JSON output format
     $this->setRequestedFormat('json');
     //create a HTTP request object and call
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/HttpRequest.php';
     $request = new HttpRequest();
     if (!$request->execute($this->endpoint, 'GET', null, null, $this->queryParameters, $response, $responseHeaders)) {
         $this->errorMessage = 'Error during request';
         //error during HTTP request
         return false;
     }
     //decode response
     if ($this->format === 'json') {
         $response = json_decode($response);
         if (json_last_error() !== JSON_ERROR_NONE) {
             $this->errorMessage = 'Invalid response received';
             //error on JSON parsing
             return false;
         }
         //return object
         return $response;
     }
     //return false by default
     return false;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:31,代码来源:MusicBrainz.php

示例2: executeCall

 /**
  * Execute a HTTP request to Cover Art Archive server, errorMessage attribute is set in case of error.
  *
  * @return bool|string MusicBrainz informations or false on failure
  */
 private function executeCall()
 {
     //create a HTTP request object and call
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/HttpRequest.php';
     $request = new HttpRequest();
     if (!$request->execute($this->endpoint, 'GET', null, null, null, $response, $responseHeaders)) {
         $this->errorMessage = 'Error during request';
         //error during HTTP request
         return false;
     }
     //return object
     return $response;
 }
开发者ID:nioc,项目名称:web-music-player,代码行数:18,代码来源:CoverArtArchive.php

示例3: HttpResponse

 function test_cache_entry_exists_and_no_validation_required()
 {
     $response = new HttpResponse();
     $response->status_code = 200;
     $response->body = 'scooby';
     $request = new HttpRequest('GET', 'http://example.org/');
     $cache = new FakeCache();
     $cache->save($response, $request->cache_id());
     $request->set_cache($cache);
     $request->always_validate_cache(FALSE);
     $new_response = $request->execute();
     $this->assertEquals('scooby', $new_response->body);
 }
开发者ID:risis-eu,项目名称:RISIS_LinkedDataAPI,代码行数:13,代码来源:httprequest.test.php

示例4: execute

 public function execute()
 {
     parent::execute();
     // At least on Centos 4.8 with PHP 5.1.6, using max_redirects to follow redirects
     // causes a segfault
     if (version_compare('5.1.7', phpversion(), '>')) {
         $this->manuallyRedirect = true;
     }
     if ($this->parsedUrl['scheme'] != 'http') {
         $this->status->fatal('http-invalid-scheme', $this->parsedUrl['scheme']);
     }
     $this->reqHeaders['Accept'] = "*/*";
     if ($this->method == 'POST') {
         // Required for HTTP 1.0 POSTs
         $this->reqHeaders['Content-Length'] = strlen($this->postData);
         $this->reqHeaders['Content-type'] = "application/x-www-form-urlencoded";
     }
     $options = array();
     if ($this->proxy && !$this->noProxy) {
         $options['proxy'] = $this->urlToTCP($this->proxy);
         $options['request_fulluri'] = true;
     }
     if (!$this->followRedirects || $this->manuallyRedirect) {
         $options['max_redirects'] = 0;
     } else {
         $options['max_redirects'] = $this->maxRedirects;
     }
     $options['method'] = $this->method;
     $options['header'] = implode("\r\n", $this->getHeaderList());
     // Note that at some future point we may want to support
     // HTTP/1.1, but we'd have to write support for chunking
     // in version of PHP < 5.3.1
     $options['protocol_version'] = "1.0";
     // This is how we tell PHP we want to deal with 404s (for example) ourselves.
     // Only works on 5.2.10+
     $options['ignore_errors'] = true;
     if ($this->postData) {
         $options['content'] = $this->postData;
     }
     $oldTimeout = false;
     if (version_compare('5.2.1', phpversion(), '>')) {
         $oldTimeout = ini_set('default_socket_timeout', $this->timeout);
     } else {
         $options['timeout'] = $this->timeout;
     }
     $context = stream_context_create(array('http' => $options));
     $this->headerList = array();
     $reqCount = 0;
     $url = $this->url;
     do {
         $again = false;
         $reqCount++;
         wfSuppressWarnings();
         $fh = fopen($url, "r", false, $context);
         wfRestoreWarnings();
         if ($fh) {
             $result = stream_get_meta_data($fh);
             $this->headerList = $result['wrapper_data'];
             $this->parseHeader();
             $url = $this->getResponseHeader("Location");
             $again = $this->manuallyRedirect && $this->followRedirects && $url && $this->isRedirect() && $this->maxRedirects > $reqCount;
         }
     } while ($again);
     if ($oldTimeout !== false) {
         ini_set('default_socket_timeout', $oldTimeout);
     }
     $this->setStatus();
     if ($fh === false) {
         $this->status->fatal('http-request-error');
         return $this->status;
     }
     if ($result['timed_out']) {
         $this->status->fatal('http-timed-out', $this->url);
         return $this->status;
     }
     if ($this->status->isOK()) {
         while (!feof($fh)) {
             $buf = fread($fh, 8192);
             if ($buf === false) {
                 $this->status->fatal('http-read-error');
                 break;
             }
             if (strlen($buf)) {
                 call_user_func($this->callback, $fh, $buf);
             }
         }
     }
     fclose($fh);
     return $this->status;
 }
开发者ID:rocLv,项目名称:conference,代码行数:90,代码来源:HttpFunctions.php


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