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


PHP HTTPClient::userAgent方法代码示例

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


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

示例1: 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');
    try {
        $profile = $notice->getProfile();
    } catch (Exception $e) {
        // @todo: distinguish the 'broken notice/profile' case from more general
        //        transitory errors.
        common_log(LOG_ERR, "Exception getting notice profile: " . $e->getMessage());
        return true;
    }
    $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: ' . HTTPClient::userAgent()));
                } else {
                    $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: ' . HTTPClient::userAgent()));
                }
                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:bashrc,项目名称:gnusocial-debian,代码行数:62,代码来源:ping.php

示例2: userAgent

 protected function userAgent()
 {
     return HTTPClient::userAgent() . ' (' . get_class($this) . ' v' . $this->version() . ')';
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:4,代码来源:plugin.php

示例3: httpOpen

 /**
  * Build HTTP request headers.
  *
  * @param string $host
  * @param string $path
  * @return string
  */
 protected function httpOpen($host, $path)
 {
     $lines = array("GET {$path} HTTP/1.1", "Host: {$host}", 'User-Agent: ' . HTTPClient::userAgent() . ' (TwitterBridgePlugin)', "Connection: close", "", "");
     return implode(self::CRLF, $lines);
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:12,代码来源:jsonstreamreader.php


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