當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HTTP_Request2類代碼示例

本文整理匯總了PHP中HTTP_Request2的典型用法代碼示例。如果您正苦於以下問題:PHP HTTP_Request2類的具體用法?PHP HTTP_Request2怎麽用?PHP HTTP_Request2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了HTTP_Request2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: erzData

 public function erzData($zip = null, $type = null, $page = 1)
 {
     if ($type) {
         $url = 'http://openerz.herokuapp.com:80/api/calendar/' . $type . '.json';
     } else {
         $url = 'http://openerz.herokuapp.com:80/api/calendar.json';
     }
     //Http-request
     $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
     $reqUrl = $request->getUrl();
     $pageSize = 10;
     $reqUrl->setQueryVariable('limit', $pageSize);
     $offset = ($page - 1) * $pageSize;
     $reqUrl->setQueryVariable('offset', $offset);
     if ($zip) {
         $reqUrl->setQueryVariable('zip', $zip);
     }
     try {
         $response = $request->send();
         // 200 ist für den Status ob ok ist 404 wäre zum Beispiel ein Fehler
         if ($response->getStatus() == 200) {
             return json_decode($response->getBody());
         }
     } catch (HTTP_Request2_Exception $ex) {
         echo $ex;
     }
     return null;
 }
開發者ID:Nithuja,項目名稱:ERZ,代碼行數:28,代碼來源:index.php

示例2: main

 /**
  * Make the GET request
  *
  * @throws BuildException
  */
 public function main()
 {
     if (!isset($this->url)) {
         throw new BuildException("Missing attribute 'url'");
     }
     if (!isset($this->dir)) {
         throw new BuildException("Missing attribute 'dir'");
     }
     $this->log("Fetching " . $this->url);
     $request = new HTTP_Request2($this->url);
     $response = $request->send();
     if ($response->getStatus() != 200) {
         throw new BuildException("Request unsuccessfull. Response from server: " . $response->getStatus() . " " . $response->getReasonPhrase());
     }
     $content = $response->getBody();
     if ($this->filename) {
         $filename = $this->filename;
     } elseif ($disposition = $response->getHeader('content-disposition') && 0 == strpos($disposition, 'attachment') && preg_match('/filename="([^"]+)"/', $disposition, $m)) {
         $filename = basename($m[1]);
     } else {
         $filename = basename(parse_url($this->url, PHP_URL_PATH));
     }
     if (!is_writable($this->dir)) {
         throw new BuildException("Cannot write to directory: " . $this->dir);
     }
     $filename = $this->dir . "/" . $filename;
     file_put_contents($filename, $content);
     $this->log("Contents from " . $this->url . " saved to {$filename}");
 }
開發者ID:altesien,項目名稱:FinalProject,代碼行數:34,代碼來源:HttpGetTask.php

示例3: __construct

 private function __construct()
 {
     // sanity check
     $siteUrl = get_option('siteurl');
     $layoutUrl = DAIQUIRI_URL . '/core/layout/';
     if (strpos($layoutUrl, $siteUrl) !== false) {
         echo '<h1>Error with theme</h1><p>Layout URL is below CMS URL.</p>';
         die(0);
     }
     // construct request
     require_once 'HTTP/Request2.php';
     $req = new HTTP_Request2($layoutUrl);
     $req->setConfig(array('ssl_verify_peer' => false, 'connect_timeout' => 2, 'timeout' => 3));
     $req->setMethod('GET');
     $req->addCookie("PHPSESSID", $_COOKIE["PHPSESSID"]);
     try {
         $response = $req->send();
         if (200 != $response->getStatus()) {
             echo '<h1>Error with theme</h1><p>HTTP request status != 200.</p>';
             die(0);
         }
     } catch (HTTP_Request2_Exception $e) {
         echo '<h1>Error with theme</h1><p>Error with HTTP request.</p>';
         die(0);
     }
     $body = explode('<!-- content -->', $response->getBody());
     if (count($body) == 2) {
         $this->_header = $body[0];
         $this->_footer = $body[1];
     } else {
         echo '<h1>Error with theme</h1><p>Malformatted layout.</p>';
         die(0);
     }
 }
開發者ID:vrtulka23,項目名稱:daiquiri,代碼行數:34,代碼來源:functions.php

示例4: sendRequest

 /**
  * {@inheritdoc }
  */
 public function sendRequest(\HTTP_Request2 $request)
 {
     if (array_key_exists($request->getMethod(), array_flip($this->getDisallowedMethods()))) {
         throw new NotAllowedMethodTypeException();
     }
     return parent::sendRequest($request);
 }
開發者ID:mobilerider,項目名稱:mobilerider-client-php,代碼行數:10,代碼來源:BaseAdapter.php

示例5: getRss

function getRss($url, $port, $timeout)
{
    $results = array('rss' => array(), 'error' => "");
    try {
        $request = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
        $request->setConfig("connect_timeout", $timeout);
        $request->setConfig("timeout", $timeout);
        $request->setHeader("user-agent", $_SERVER['HTTP_USER_AGENT']);
        $response = $request->send();
        if ($response->getStatus() == 200) {
            // パース
            $body = $response->getBody();
            if (substr($body, 0, 5) == "<?xml") {
                $results['rss'] = new MagpieRSS($body, "UTF-8");
            } else {
                throw new Exception("Not xml data");
            }
        } else {
            throw new Exception("Server returned status: " . $response->getStatus());
        }
    } catch (HTTP_Request2_Exception $e) {
        $results['error'] = $e->getMessage();
    } catch (Exception $e) {
        $results['error'] = $e->getMessage();
    }
    // タイムアウト戻し
    ini_set('default_socket_timeout', $oldtimeout);
    return $results;
}
開發者ID:homework-bazaar,項目名稱:zencart-sugu,代碼行數:29,代碼來源:functions.php

示例6: testSetRequest

 public function testSetRequest()
 {
     $newswire = new Newswire('apikey');
     $req = new \HTTP_Request2();
     $req->setAdapter('mock');
     $this->assertInstanceOf('PEAR2\\Services\\NYTimes\\Newswire', $newswire->accept($req));
 }
開發者ID:pear2,項目名稱:services_nytimes,代碼行數:7,代碼來源:BaseTest.php

示例7: setUp

 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->mock = new HTTP_Request2_Adapter_Mock();
     $request = new HTTP_Request2();
     $request->setAdapter($this->mock);
     $this->validator = new Services_W3C_CSSValidator($request);
 }
開發者ID:pear,項目名稱:services_w3c_cssvalidator,代碼行數:13,代碼來源:Services_W3C_CSSValidatorTest.php

示例8: getLanguagesFromTransifex

 public function getLanguagesFromTransifex()
 {
     $request = new HTTP_Request2('http://vela1606:pass@www.transifex.net/api/2/project/gaiaehr/resource/All/?details', HTTP_Request2::METHOD_GET);
     $r = $request->send()->getBody();
     $r = json_decode($r, true);
     return array('langs' => $r['available_languages']);
 }
開發者ID:nhom5UET,項目名稱:tichhophethong,代碼行數:7,代碼來源:Languages.php

示例9: fetchLunchMenus

 /**
  * さくら水産のランチ情報を取得する
  *
  * @return array | false
  */
 public function fetchLunchMenus()
 {
     $menus = array();
     $today = new DateTime();
     $request = new HTTP_Request2();
     $request->setMethod(HTTP_Request2::METHOD_GET);
     $request->setUrl(self::LUNCHMENU_URL);
     try {
         $response = $request->send();
         if (200 == $response->getStatus()) {
             $dom = new DOMDocument();
             @$dom->loadHTML($response->getBody());
             $xml = simplexml_import_dom($dom);
             foreach ($xml->xpath('//table/tr') as $tr) {
                 if (preg_match('/(\\d+)月(\\d+)日/', $tr->td[0]->div, $matches)) {
                     $dateinfo = new DateTime(sprintf('%04d-%02d-%02d', $today->format('Y'), $matches[1], $matches[2]));
                     $_menus = array();
                     foreach ($tr->td[1]->div->strong as $strong) {
                         $_menus[] = (string) $strong;
                     }
                     $menus[$dateinfo->format('Y-m-d')] = $_menus;
                 }
             }
         }
     } catch (HTTP_Request2_Exception $e) {
         // HTTP Error
         return false;
     }
     return $menus;
 }
開發者ID:riaf,項目名稱:Wozozo_Sakusui,代碼行數:35,代碼來源:Sakusui.php

示例10: send_post_data

function send_post_data($url, $data)
{
    require_once 'HTTP/Request2.php';
    $request = new HTTP_Request2($url);
    $request->setMethod(HTTP_Request2::METHOD_POST)->addPostParameter($data);
    return $request->send();
}
開發者ID:jabouzi,項目名稱:belron,代碼行數:7,代碼來源:functions_helper.php

示例11: twipic

function twipic($f, $a, $b, $m)
{
    $twitpic_api = "";
    $consumer_key = "";
    $consumer_secret = "";
    $access_token = $a;
    $access_token_secret = $b;
    $imagepath = $f;
    $message = $me;
    $consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
    $consumer->setToken($access_token);
    $consumer->setTokenSecret($access_token_secret);
    $http_request = new HTTP_Request2();
    $http_request->setConfig('ssl_verify_peer', false);
    $consumer_request = new HTTP_OAuth_Consumer_Request();
    $consumer_request->accept($http_request);
    $consumer->accept($consumer_request);
    $resp = $consumer->sendRequest('https://api.twitter.com/1.1/account/verify_credentials.json', array(), HTTP_Request2::METHOD_GET);
    $headers = $consumer->getLastRequest()->getHeaders();
    $http_request->setHeader('X-Auth-Service-Provider', 'https://api.twitter.com/1.1/account/verify_credentials.json');
    $http_request->setHeader('X-Verify-Credentials-Authorization', $headers['authorization']);
    $http_request->setUrl('http://api.twitpic.com/2/upload.json');
    $http_request->setMethod(HTTP_Request2::METHOD_POST);
    $http_request->addPostParameter('key', $twitpic_api);
    $http_request->addPostParameter('message', $m);
    $http_request->addUpload('media', $imagepath);
    $resp = $http_request->send();
    $body = $resp->getBody();
    $body = json_decode($body, true);
    return $body;
}
開發者ID:book000,項目名稱:mcmn,代碼行數:31,代碼來源:twipic.php

示例12: setRequestHeaders

 /**
  * Sets the common headers required by CloudFront API
  * @param HTTP_Request2 $req
  */
 private function setRequestHeaders(HTTP_Request2 $req)
 {
     $date = gmdate("D, d M Y G:i:s T");
     $req->setHeader("Host", 'cloudfront.amazonaws.com');
     $req->setHeader("Date", $date);
     $req->setHeader("Authorization", $this->generateAuthKey($date));
     $req->setHeader("Content-Type", "text/xml");
 }
開發者ID:subchild,項目名稱:CloudFront-PHP-Invalidator,代碼行數:12,代碼來源:CloudFront.php

示例13: testConfigurationViaProperties

 public function testConfigurationViaProperties()
 {
     $trace = new TraceHttpAdapter();
     $this->copyTasksAddingCustomRequest('config-properties', 'recipient', $this->createRequest($trace));
     $this->executeTarget('recipient');
     $request = new HTTP_Request2(null, 'GET', array('proxy' => 'http://localhost:8080/', 'max_redirects' => 9));
     $this->assertEquals($request->getConfig(), $trace->requests[0]['config']);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:8,代碼來源:HttpRequestTaskTest.php

示例14: addHttpMock

 protected function addHttpMock(Net_WebFinger $wf)
 {
     $this->adapter = new HTTP_Request2_Adapter_LogMock();
     $req = new HTTP_Request2();
     $req->setAdapter($this->adapter);
     $wf->setHttpClient($req);
     return $this;
 }
開發者ID:mitgedanken,項目名稱:Net_WebFinger,代碼行數:8,代碼來源:WebFingerTestBase.php

示例15: testBug17826

 public function testBug17826()
 {
     $adapter = new HTTP_Request2_Adapter_Socket();
     $request1 = new HTTP_Request2($this->baseUrl . 'redirects.php?redirects=2');
     $request1->setConfig(array('follow_redirects' => true, 'max_redirects' => 3))->setAdapter($adapter)->send();
     $request2 = new HTTP_Request2($this->baseUrl . 'redirects.php?redirects=2');
     $request2->setConfig(array('follow_redirects' => true, 'max_redirects' => 3))->setAdapter($adapter)->send();
 }
開發者ID:rogerwu99,項目名稱:punch_bantana,代碼行數:8,代碼來源:SocketTest.php


注:本文中的HTTP_Request2類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。