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


PHP HTTPClient::start方法代码示例

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


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

示例1: linkback_get_target

function linkback_get_target($target)
{
    // Resolve target (https://github.com/converspace/webmention/issues/43)
    $request = HTTPClient::start();
    try {
        $response = $request->head($target);
    } catch (Exception $ex) {
        return NULL;
    }
    try {
        $notice = Notice::fromUri($response->getEffectiveUrl());
    } catch (UnknownUriException $ex) {
        preg_match('/\\/notice\\/(\\d+)(?:#.*)?$/', $response->getEffectiveUrl(), $match);
        $notice = Notice::getKV('id', $match[1]);
    }
    if ($notice instanceof Notice && $notice->isLocal()) {
        return $notice;
    } else {
        $user = User::getKV('uri', $response->getEffectiveUrl());
        if (!$user) {
            preg_match('/\\/user\\/(\\d+)(?:#.*)?$/', $response->getEffectiveUrl(), $match);
            $user = User::getKV('id', $match[1]);
        }
        if (!$user) {
            preg_match('/\\/([^\\/\\?#]+)(?:#.*)?$/', $response->getEffectiveUrl(), $match);
            if (linkback_lenient_target_match(common_profile_url($match[1]), $response->getEffectiveUrl())) {
                $user = User::getKV('nickname', $match[1]);
            }
        }
        if ($user instanceof User) {
            return $user;
        }
    }
    return NULL;
}
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:35,代码来源:util.php

示例2: onStartShowSections

 function onStartShowSections($action)
 {
     $name = $action->trimmed('action');
     if ($name == 'tag') {
         $taginput = $action->trimmed('tag');
         $tag = common_canonical_tag($taginput);
         if (!empty($tag)) {
             $url = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=render', urlencode($tag));
             $editurl = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=edit', urlencode($tag));
             $request = HTTPClient::start();
             $response = $request->get($url);
             $html = $response->getBody();
             $action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section'));
             if ($response->isOk() && !empty($html)) {
                 $action->element('style', null, "span.editsection { display: none }\n" . "table.toc { display: none }");
                 $action->raw($html);
                 $action->elementStart('p');
                 $action->element('a', array('href' => $editurl, 'title' => sprintf(_m('Edit the article for #%s on WikiHashtags'), $tag)), _m('Edit'));
                 $action->element('a', array('href' => 'http://www.gnu.org/copyleft/fdl.html', 'title' => _m('Shared under the terms of the GNU Free Documentation License'), 'rel' => 'license'), _m('GNU FDL'));
                 $action->elementEnd('p');
             } else {
                 $action->element('a', array('href' => $editurl), sprintf(_m('Start the article for #%s on WikiHashtags'), $tag));
             }
             $action->elementEnd('div');
         }
     }
     return true;
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:28,代码来源:WikiHashtagsPlugin.php

示例3: httpRequest

function httpRequest($endpoint, $poststr)
{
    $request = HTTPClient::start();
    $request->setConfig(array('follow_redirects' => true, 'connect_timeout' => 120, 'timeout' => 120, 'ssl_verify_peer' => false, 'ssl_verify_host' => false));
    // Turn signed request query string back into an array
    parse_str($poststr, $postdata);
    return $request->post($endpoint, null, $postdata);
}
开发者ID:microcosmx,项目名称:experiments,代码行数:8,代码来源:oauth_post_notice.php

示例4: ping_broadcast_notice

function ping_broadcast_notice($notice)
{
    if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) {
        return true;
    }
    # Array of servers, URL => type
    $notify = common_config('ping', 'notify');
    $profile = $notice->getProfile();
    $tags = ping_notice_tags($notice);
    foreach ($notify as $notify_url => $type) {
        switch ($type) {
            case 'xmlrpc':
            case 'extended':
                $req = xmlrpc_encode_request('weblogUpdates.ping', array($profile->nickname, common_local_url('showstream', array('nickname' => $profile->nickname)), common_local_url('shownotice', array('notice' => $notice->id)), common_local_url('userrss', array('nickname' => $profile->nickname)), $tags));
                $request = HTTPClient::start();
                $request->setConfig('connect_timeout', common_config('ping', 'timeout'));
                $request->setConfig('timeout', common_config('ping', 'timeout'));
                try {
                    $httpResponse = $request->post($notify_url, array('Content-Type: text/xml'), $req);
                } catch (Exception $e) {
                    common_log(LOG_ERR, "Exception pinging {$notify_url}: " . $e->getMessage());
                    continue;
                }
                if (!$httpResponse || mb_strlen($httpResponse->getBody()) == 0) {
                    common_log(LOG_WARNING, "XML-RPC empty results for ping ({$notify_url}, {$notice->id}) ");
                    continue;
                }
                $response = xmlrpc_decode($httpResponse->getBody());
                if (is_array($response) && xmlrpc_is_fault($response)) {
                    common_log(LOG_WARNING, "XML-RPC error for ping ({$notify_url}, {$notice->id}) " . "{$response['faultString']} ({$response['faultCode']})");
                } else {
                    common_log(LOG_INFO, "Ping success for {$notify_url} {$notice->id}");
                }
                break;
            case 'get':
            case 'post':
                $args = array('name' => $profile->nickname, 'url' => common_local_url('showstream', array('nickname' => $profile->nickname)), 'changesURL' => common_local_url('userrss', array('nickname' => $profile->nickname)));
                $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
                if ($type === 'get') {
                    $result = $fetcher->get($notify_url . '?' . http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_VERSION));
                } else {
                    $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_VERSION));
                }
                if ($result->status != '200') {
                    common_log(LOG_WARNING, "Ping error for '{$notify_url}' ({$notice->id}): " . "{$result->body}");
                } else {
                    common_log(LOG_INFO, "Ping success for '{$notify_url}' ({$notice->id}): " . "'{$result->body}'");
                }
                break;
            default:
                common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
        }
    }
    return true;
}
开发者ID:Br3nda,项目名称:StatusNet,代码行数:55,代码来源:ping.php

示例5: doSpotifyLookup

function doSpotifyLookup($uri, $isArtist)
{
    $request = HTTPClient::start();
    $response = $request->get('http://ws.spotify.com/lookup/1/?uri=' . $uri);
    if ($response->isOk()) {
        $xml = simplexml_load_string($response->getBody());
        if ($isArtist) {
            return $xml->name;
        } else {
            return $xml->artist->name . ' - ' . $xml->name;
        }
    }
}
开发者ID:Grasia,项目名称:bolotweet,代码行数:13,代码来源:SpotifyPlugin.php

示例6: mention_url_representative_hcard

function mention_url_representative_hcard($url, $fn = null, $mf2 = null)
{
    if (!$mf2) {
        $request = HTTPClient::start();
        try {
            $response = $request->get($url);
        } catch (Exception $ex) {
            return null;
        }
        $url = $response->getEffectiveUrl();
        $mf2 = new Mf2\Parser($response->getBody(), $url);
        $mf2 = $mf2->parse();
    }
    $hcard = null;
    if (!empty($mf2['items'])) {
        $hcards = array();
        foreach ($mf2['items'] as $item) {
            if (!in_array('h-card', $item['type'])) {
                continue;
            }
            // We found a match, return it immediately
            if (isset($item['properties']['url']) && in_array($url, $item['properties']['url'])) {
                $hcard = $item['properties'];
                break;
            }
            // Let's keep all the hcards for later, to return one of them at least
            $hcards[] = $item['properties'];
        }
        // No match immediately for the url we expected, but there were h-cards found
        if (count($hcards) > 0) {
            $hcard = $hcards[0];
        }
    }
    if (!$hcard && $fn) {
        $hcard = array('name' => array($fn));
    }
    if (!$hcard && $response) {
        preg_match('/<title>([^<]+)/', $response->getBody(), $match);
        $hcard = array('name' => array($match[1]));
    }
    if ($hcard && !$hcard['url']) {
        $hcard['url'] = array($url);
    }
    return $hcard;
}
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:45,代码来源:util.php

示例7: handle

 function handle($notice)
 {
     $profile = Profile::staticGet($notice->profile_id);
     $this->log(LOG_INFO, "Posting Notice " . $notice->id . " from " . $profile->nickname);
     if (!$notice->is_local) {
         $this->log(LOG_INFO, "Skipping remote notice");
         return "skipped";
     }
     #
     # Build an Atom message from the notice
     #
     $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
     $msg = $profile->nickname . ': ' . $notice->content;
     $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
     $atom .= "<apisource>" . common_config('enjit', 'source') . "</apisource>\n";
     $atom .= "<source>\n";
     $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
     $atom .= "<link href='" . $profile->profileurl . "'/>\n";
     $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
     $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
     $atom .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
     $atom .= "</source>\n";
     $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
     $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
     $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
     $atom .= "<id>" . $notice->uri . "</id>\n";
     $atom .= "<published>" . common_date_w3dtf($notice->created) . "</published>\n";
     $atom .= "<updated>" . common_date_w3dtf($notice->modified) . "</updated>\n";
     $atom .= "</entry>\n";
     $url = common_config('enjit', 'apiurl') . "/submit/" . common_config('enjit', 'apikey');
     $data = array('msg' => $atom);
     #
     # POST the message to $config['enjit']['apiurl']
     #
     $request = HTTPClient::start();
     $response = $request->post($url, null, $data);
     return $response->isOk();
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:38,代码来源:enjitqueuehandler.php

示例8: report

 /**
  * Reports statistics to headquarters
  *
  * Posts statistics to a reporting server.
  *
  * @return void
  */
 function report()
 {
     // XXX: Use OICU2 and OAuth to make authorized requests
     $reporturl = common_config('snapshot', 'reporturl');
     try {
         $request = HTTPClient::start();
         $request->post($reporturl, null, $this->stats);
     } catch (Exception $e) {
         common_log(LOG_WARNING, "Error in snapshot: " . $e->getMessage());
     }
 }
开发者ID:himmelex,项目名称:NTW,代码行数:18,代码来源:snapshot.php

示例9: httpGet

 /**
  * Make an HTTP GET request with OAuth headers and return an HTTPResponse
  * with the returned body and codes.
  *
  * @param string $url
  * @return HTTPResponse
  *
  * @throws Exception on low-level network error
  */
 protected function httpGet($url)
 {
     $headers = array('Authorization: ' . $this->authHeader());
     $client = HTTPClient::start();
     return $client->get($url, $headers);
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:15,代码来源:sn_yammerclient.php

示例10: getGeonames

 function getGeonames($method, $params)
 {
     if ($this->lastTimeout && time() - $this->lastTimeout < $this->timeoutWindow) {
         // TRANS: Exception thrown when a geo names service is not used because of a recent timeout.
         throw new Exception(_m('Skipping due to recent web service timeout.'));
     }
     $client = HTTPClient::start();
     $client->setConfig('connect_timeout', $this->timeout);
     $client->setConfig('timeout', $this->timeout);
     try {
         $result = $client->get($this->wsUrl($method, $params));
     } catch (Exception $e) {
         common_log(LOG_ERR, __METHOD__ . ": " . $e->getMessage());
         $this->lastTimeout = time();
         throw $e;
     }
     if (!$result->isOk()) {
         // TRANS: Exception thrown when a geo names service does not return an expected response.
         // TRANS: %s is an HTTP error code.
         throw new Exception(sprintf(_m('HTTP error code %s.'), $result->getStatus()));
     }
     $body = $result->getBody();
     if (empty($body)) {
         // TRANS: Exception thrown when a geo names service returns an empty body.
         throw new Exception(_m('Empty HTTP body in response.'));
     }
     // This will throw an exception if the XML is mal-formed
     $document = new SimpleXMLElement($body);
     // No children, usually no results
     $children = $document->children();
     if (count($children) == 0) {
         return array();
     }
     if (isset($document->status)) {
         // TRANS: Exception thrown when a geo names service return a specific error number and error text.
         // TRANS: %1$s is an error code, %2$s is an error message.
         throw new Exception(sprintf(_m('Error #%1$s ("%2$s").'), $document->status['value'], $document->status['message']));
     }
     // Array of elements, >0 elements
     return $document->geoname;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:41,代码来源:GeonamesPlugin.php

示例11: httpRequest

 /**
  * Make an HTTP request
  *
  * @param string $url    Where to make the request
  * @param array  $params post parameters
  *
  * @return mixed the request
  * @throws BasicAuthException
  */
 function httpRequest($url, $params = null, $auth = true)
 {
     $request = HTTPClient::start();
     $request->setConfig(array('follow_redirects' => true, 'connect_timeout' => 120, 'timeout' => 120, 'ssl_verify_peer' => false, 'ssl_verify_host' => false));
     if ($auth) {
         $request->setAuth($this->screen_name, $this->password);
     }
     if (isset($params)) {
         // Twitter is strict about accepting invalid "Expect" headers
         $headers = array('Expect:');
         $response = $request->post($url, $headers, $params);
     } else {
         $response = $request->get($url);
     }
     $code = $response->getStatus();
     if ($code < 200 || $code >= 400) {
         throw new BasicAuthException($response->getBody(), $code);
     }
     return $response->getBody();
 }
开发者ID:himmelex,项目名称:NTW,代码行数:29,代码来源:twitterbasicauthclient.php

示例12: query

 /**
  * Inject API key into query before sending out...
  *
  * @param string $url
  * @return HTTPResponse
  */
 protected function query($url)
 {
     // http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/shorten
     $params = http_build_query(array('login' => $this->getLogin(), 'apiKey' => $this->getApiKey()), '', '&');
     $serviceUrl = sprintf($this->serviceUrl, $url) . '&' . $params;
     $request = HTTPClient::start();
     return $request->get($serviceUrl);
 }
开发者ID:stevertiqo,项目名称:StatusNet,代码行数:14,代码来源:BitlyUrlPlugin.php

示例13: fetchRemoteUrl

 /**
  * Fetch a remote avatar image and save to local storage.
  *
  * @param string $url avatar source URL
  * @param string $filename bare local filename for download
  * @return bool true on success, false on failure
  */
 protected function fetchRemoteUrl($url, $filename)
 {
     common_debug(__METHOD__ . " - Fetching Twitter avatar: {$url} to {$filename}");
     $request = HTTPClient::start();
     $request->setConfig('connect_timeout', 3);
     // I had problems with throttling
     $request->setConfig('timeout', 6);
     // and locking the process sucks.
     $response = $request->get($url);
     if ($response->isOk()) {
         if (!file_put_contents($filename, $response->getBody())) {
             throw new ServerException('Failed saving fetched file');
         }
     } else {
         throw new Exception('Unexpected HTTP status code');
     }
     return true;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:25,代码来源:twitterimport.php

示例14: http_post

 /**
  * Utility to post a request and get a response URL
  *
  * @param string $url  URL to fetch
  * @param array  $data post parameters
  *
  * @return string response body
  *
  * @todo rename to code-standard httpPost()
  */
 protected function http_post($url, $data)
 {
     $request = HTTPClient::start();
     $response = $request->post($url, null, $data);
     return $response->getBody();
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:16,代码来源:urlshortenerplugin.php

示例15: getGeonames

 function getGeonames($method, $params)
 {
     if ($this->lastTimeout && time() - $this->lastTimeout < $this->timeoutWindow) {
         throw new Exception("skipping due to recent web service timeout");
     }
     $client = HTTPClient::start();
     $client->setConfig('connect_timeout', $this->timeout);
     $client->setConfig('timeout', $this->timeout);
     try {
         $result = $client->get($this->wsUrl($method, $params));
     } catch (Exception $e) {
         common_log(LOG_ERR, __METHOD__ . ": " . $e->getMessage());
         $this->lastTimeout = time();
         throw $e;
     }
     if (!$result->isOk()) {
         throw new Exception("HTTP error code " . $result->getStatus());
     }
     $body = $result->getBody();
     if (empty($body)) {
         throw new Exception("Empty HTTP body in response");
     }
     // This will throw an exception if the XML is mal-formed
     $document = new SimpleXMLElement($body);
     // No children, usually no results
     $children = $document->children();
     if (count($children) == 0) {
         return array();
     }
     if (isset($document->status)) {
         throw new Exception("Error #" . $document->status['value'] . " ('" . $document->status['message'] . "')");
     }
     // Array of elements, >0 elements
     return $document->geoname;
 }
开发者ID:Br3nda,项目名称:StatusNet,代码行数:35,代码来源:GeonamesPlugin.php


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