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


PHP HTTP_Request2::setConfig方法代码示例

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


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

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

示例2: __construct

    /**
     *
     * @param TW2MV_Configure
     */
    public function __construct($config)
    {
        try {
            $this->http = new HTTP_Request2();
            $this->http->setConfig('ssl_verify_peer', false);

        } catch (Exception $e) {
            debug($e->getMessage());

        }

        $this->config = $config;
    }
开发者ID:nojimage,项目名称:twitter2mixivoice,代码行数:17,代码来源:Client.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: request

 private function request($method, $path, $params = array())
 {
     $url = $this->api . rtrim($path, '/') . '/';
     if (!strcmp($method, "POST")) {
         $req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
         $req->setHeader('Content-type: application/json');
         if ($params) {
             $req->setBody(json_encode($params));
         }
     } else {
         if (!strcmp($method, "GET")) {
             $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
             $url = $req->getUrl();
             $url->setQueryVariables($params);
         } else {
             if (!strcmp($method, "DELETE")) {
                 $req = new HTTP_Request2($url, HTTP_Request2::METHOD_DELETE);
                 $url = $req->getUrl();
                 $url->setQueryVariables($params);
             }
         }
     }
     $req->setAdapter('curl');
     $req->setConfig(array('timeout' => 30));
     $req->setAuth($this->auth_id, $this->auth_token, HTTP_Request2::AUTH_BASIC);
     $req->setHeader(array('Connection' => 'close', 'User-Agent' => 'PHPPlivo'));
     $r = $req->send();
     $status = $r->getStatus();
     $body = $r->getbody();
     $response = json_decode($body, true);
     return array("status" => $status, "response" => $response);
 }
开发者ID:davidangelcb,项目名称:voice,代码行数:32,代码来源:plivo.php

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

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

示例7: getRequest

 protected function getRequest()
 {
     if (!$this->request instanceof HTTP_Request2) {
         $this->request = new HTTP_Request2();
         $this->request->setConfig(array('connect_timeout' => 1, 'timeout' => 3));
     }
     return clone $this->request;
 }
开发者ID:GervaisdeM,项目名称:news-flash,代码行数:8,代码来源:NewsFlashRSSSource.php

示例8: getClient

 /**
  * Creates a HTTP client if none is set.
  *
  * @return \HTTP_Request2
  */
 public function getClient()
 {
     if (false === $this->client instanceof \HTTP_Request2) {
         $this->client = new \HTTP_Request2();
         $this->client->setConfig(array('adapter' => 'HTTP_Request2_Adapter_Curl', 'timeout' => 3, 'max_redirects' => 1));
     }
     $this->client->setAuth($this->publicKey, $this->privateKey);
     return $this->client;
 }
开发者ID:easybib,项目名称:services_oneall,代码行数:14,代码来源:OneAll.php

示例9: testTimeout

 public function testTimeout()
 {
     $this->request->setConfig('timeout', 2);
     try {
         $this->request->send();
         $this->fail('Expected HTTP_Request2_Exception was not thrown');
     } catch (HTTP_Request2_Exception $e) {
     }
 }
开发者ID:rogerwu99,项目名称:punch_bantana,代码行数:9,代码来源:CommonNetworkTest.php

示例10: update

 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://hacker-news.firebaseio.com/v0/user/' . $username . '.json');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $karma = json_decode($response)->karma;
     Score::update(self::name, $userid, $karma);
 }
开发者ID:nsystem1,项目名称:leaderboard,代码行数:10,代码来源:hackernews.php

示例11: update

 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $username = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://open.dapper.net/transform.php?dappName=CodeChefProblemsSolved&transformer=JSON&v_username=' . $username);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $score = json_decode($response)->fields->solved[32]->value;
     Score::update(self::name, $userid, $score);
 }
开发者ID:nsystem1,项目名称:leaderboard,代码行数:10,代码来源:codechef.php

示例12: testTimeoutInRequest

 public function testTimeoutInRequest()
 {
     $this->request->setConfig('timeout', 2)->setUrl($this->baseUrl . 'postparameters.php')->setBody(new SlowpokeBody(array('foo' => 'some value'), array()));
     try {
         $this->request->send();
         $this->fail('Expected HTTP_Request2_MessageException was not thrown');
     } catch (HTTP_Request2_MessageException $e) {
         $this->assertEquals(HTTP_Request2_Exception::TIMEOUT, $e->getCode());
     }
 }
开发者ID:SuhitNarayan,项目名称:SuhitNarayan-SEMANTICTECH,代码行数:10,代码来源:CommonNetworkTest.php

示例13: update

 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $lastFMUsername = Token::get(self::name, $userid);
     $request = new HTTP_Request2('http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=' . $lastFMUsername . '&api_key=' . LASTFM_APP_ID . '&format=json');
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $playcount = trim(json_decode($response)->user->playcount);
     Score::update(self::name, $userid, $playcount);
     //Update in database
 }
开发者ID:nsystem1,项目名称:leaderboard,代码行数:11,代码来源:lastfm.php

示例14: update

 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $twitterScreenName = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://api.twitter.com/1/users/show.json?screen_name=' . $twitterScreenName);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $followers_count = json_decode($response)->followers_count;
     Score::update(self::name, $userid, $followers_count);
     //Update in database
 }
开发者ID:nsystem1,项目名称:leaderboard,代码行数:11,代码来源:twitter.php

示例15: update

 public static function update($userid)
 {
     global $HTTP_CONFIG;
     $id = Token::get(self::name, $userid);
     $request = new HTTP_Request2('https://api.stackexchange.com/2.1/users/' . $id . '?site=askubuntu&key=' . STACKEXCHANGE_KEY);
     $request->setConfig($HTTP_CONFIG);
     $response = $request->send()->getBody();
     $reputation = json_decode($response)->items[0]->reputation;
     Score::update(self::name, $userid, $reputation);
     //Update in database
 }
开发者ID:nsystem1,项目名称:leaderboard,代码行数:11,代码来源:askubuntu.php


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