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


PHP Client::setUserAgent方法代码示例

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


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

示例1: __construct

 /**
  * @param string
  * @param \Nette\Database\Context
  */
 public function __construct($cryptPassword, Context $db)
 {
     $this->cryptPassword = $cryptPassword;
     $this->baseUrl = new Url('https://nette.org/loginpoint.php');
     $this->httpClient = new Client();
     $this->httpClient->setUserAgent('Nette Addons portal authenticator');
     $this->db = $db;
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:12,代码来源:NetteOrgAuthenticator.php

示例2: setGuzzle

 /**
  * @param \Guzzle\Http\Client $guzzle
  * @return void
  */
 public function setGuzzle(Client $guzzle)
 {
     $this->guzzle = $guzzle;
     $this->guzzle->setSslVerification(false, false);
     $this->guzzle->setUserAgent('User-Agent: Mozilla/5.0 (Linux; U; Android 4.3; EN; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 PlayStation App/1.60.5/EN/EN');
     $this->guzzle->addSubscriber(new CookiePlugin(new ArrayCookieJar()));
 }
开发者ID:grit45,项目名称:gumer-psn-php,代码行数:11,代码来源:Connection.php

示例3: __construct

 /**
  * Constructor
  *
  * @param \Guzzle\Http\Client $guzzle   Guzzle instance
  * @param \Closure            $rsa      Closure for phpseclib RSA instance
  * @param StorageInterface    $storage  Storage instance
  */
 public function __construct(\Guzzle\Http\Client $guzzle, \Closure $rsa, StorageInterface $storage)
 {
     $this->guzzle = $guzzle;
     $this->guzzle->setUserAgent(AcmePhpClient::USER_AGENT);
     $this->rsa = $rsa;
     $this->storage = $storage;
 }
开发者ID:albancrommer,项目名称:acmephpc,代码行数:14,代码来源:GuzzleClient.php

示例4: __construct

 /**
  * Instantiates a YoutubeDownloader with a random User-Agent
  * @param string $videoUrl Full Youtube video url or just video ID
  * @example var downloader = new YoutubeDownloader('gmFn62dr0D8');
  * @example var downloader = new YoutubeDownloader('http://www.youtube.com/watch?v=gmFn62dr0D8');
  */
 public function __construct($videoUrl)
 {
     $this->videoId = $this->getVideoIdFromUrl($videoUrl);
     $this->webClient = new \Guzzle\Http\Client();
     $this->webClient->setUserAgent(\random_uagent());
     $this->onProgress = function ($downloadedBytes, $fileSize) {
     };
 }
开发者ID:netdragoon,项目名称:YoutubeDownloader,代码行数:14,代码来源:YoutubeDownloader.php

示例5: __construct

 /**
  * @param string $apiKey
  * @param string $apiEndpoint
  * @param string $apiVersion
  * @param bool $ssl
  */
 public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl)
 {
     $this->apiKey = $apiKey;
     $this->mgClient = new Guzzle($this->generateEndpoint($apiEndpoint, $apiVersion, $ssl));
     $this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true));
     $this->mgClient->setDefaultOption('auth', array(Api::API_USER, $this->apiKey));
     $this->mgClient->setDefaultOption('exceptions', false);
     $this->mgClient->setUserAgent(Api::SDK_USER_AGENT . '/' . Api::SDK_VERSION);
 }
开发者ID:pars5555,项目名称:hqv,代码行数:15,代码来源:RestClient.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param Credentials $credentials The credentials to use.
  */
 public function __construct(Credentials $credentials)
 {
     $this->credentials = $credentials;
     $this->apiUrl = self::ENDPOINT_URL;
     //Initialize API Client
     $this->client = new Client(self::ENDPOINT_URL);
     $this->client->setDefaultOption('auth', array($this->credentials->getEmail(), $this->credentials->getAccountKey(), 'Basic'));
     $this->client->setUserAgent(self::USER_AGENT);
 }
开发者ID:haphan,项目名称:php-rage4dns,代码行数:14,代码来源:AbstractRage4DNS.php

示例7: connect

 public function connect($errors = 0)
 {
     $client = new Client(null);
     if (!file_exists($this->_cookieFile)) {
         file_put_contents($this->_cookieFile, "");
     }
     $cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
     $client->addSubscriber($cookiePlugin);
     $client->setUserAgent('User-Agent', 'Mozilla/5.0 (Linux; U; Android 4.2.2; de-de; GT-I9195 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
     $this->_client = $client;
     try {
         $url = $this->getLoginUrl();
         $this->loginAndGetCode($url);
         $this->enterAnswer();
         $this->gatewayMe();
         $this->auth();
         $this->getSid();
         $this->utasRefreshNucId();
         $this->auth();
         $this->utasAuth();
         $this->utasQuestion();
     } catch (\Exception $e) {
         throw $e;
         // server down, gotta retry
         if ($errors < static::RETRY_ON_SERVER_DOWN && preg_match("/service unavailable/mi", $e->getMessage())) {
             $this->connect(++$errors);
         } else {
             throw new \Exception('Could not connect to the mobile endpoint.');
         }
     }
     return array("nucleusId" => $this->nucId, "userAccounts" => $this->accounts, "sessionId" => $this->sid, "phishingToken" => $this->phishingToken, "platform" => $this->_loginDetails['platform']);
 }
开发者ID:hpreowned,项目名称:FIFA15-Unofficial-API,代码行数:32,代码来源:mobile_connector.php

示例8: Connect

 public function Connect()
 {
     $client = new Client(null);
     if (!file_exists($this->_cookieFile)) {
         file_put_contents($this->_cookieFile, "");
     }
     $cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
     $client->addSubscriber($cookiePlugin);
     $client->setUserAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
     $this->_client = $client;
     $login_url = $this->GetMainPage($this->urls['main']);
     $this->Login($login_url);
     $nucleusId = $this->GetNucleusId($this->urls['nucleus']);
     $this->GetShards($nucleusId, $this->urls['shards']);
     $userAccounts = $this->GetUserAccounts($nucleusId, $this->urls['userinfo']);
     $sessionId = $this->GetSessionId($nucleusId, $userAccounts, $this->urls['session']);
     $phishing = $this->Phishing($nucleusId, $sessionId, $this->urls['phishing']);
     if (isset($phishing['debug']) && $phishing['debug'] == "Already answered question.") {
         $phishingToken = $phishing['token'];
     } else {
         $phishingToken = $this->Validate($nucleusId, $sessionId, $this->urls['validate']);
     }
     $this->_loginResponse = array("nucleusId" => $nucleusId, "userAccounts" => $userAccounts, "sessionId" => $sessionId, "phishingToken" => $phishingToken, "platform" => $this->_loginDetails['platform']);
     return $this->_loginResponse;
 }
开发者ID:hpreowned,项目名称:FIFA15-Unofficial-API,代码行数:25,代码来源:connector.php

示例9: createClient

 /**
  * Create the default Client
  *
  * @return \Klout\Klout
  */
 protected function createClient()
 {
     $client = new Client($this->apiBaseUri);
     $client->setUserAgent(__CLASS__, true);
     $this->setClient($client);
     return $this;
 }
开发者ID:oytuntez,项目名称:klout-sdk-php,代码行数:12,代码来源:Klout.php

示例10: __construct

 /**
  * @param string $username
  * @param string $password
  * @param string $country
  *
  * @throws Exception
  */
 public function __construct($username, $password, $country = 'DE')
 {
     $this->_username = $username;
     $this->_password = $password;
     $this->_country = $country;
     if (!array_key_exists($country, $this->_hostNames)) {
         throw new Exception('No hostname for the given country available.');
     }
     $this->_host = $this->_hostNames[$country];
     $this->_client = new HttpClient('https://' . $this->_host . '/');
     $this->_client->setSslVerification(false, false, 0);
     $this->_client->setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17', true);
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $this->_client->addSubscriber($cookiePlugin);
     $this->_login();
 }
开发者ID:seofood,项目名称:amazon-revenue,代码行数:23,代码来源:Client.php

示例11: send

 /**
  * Sends a request to the API
  *
  * @param [string] $url    URL for API request
  * @param [string] $method Request method (i.e. PUT, POST, DELETE, or GET)
  * @param [array]  $data   Options for request
  * @return [Guzzle\Http\Message\Response] $response
  */
 public static function send($url, $method, $data = array())
 {
     // Create a new Guzzle\Http\Client
     $browser = new Browser();
     $browser->setUserAgent(self::userAgent());
     $options = self::processOptions($data);
     $request = $browser->createRequest($method, $url, null, null, $options);
     if (!empty($data['postdata'])) {
         foreach ($data['postdata'] as $k => $v) {
             $request->setPostField($k, $v);
         }
     }
     if (!empty($data['cookies'])) {
         foreach ($data['cookies'] as $k => $v) {
             $request->addCookie($k, $v);
         }
     }
     if (!empty($data['headers'])) {
         foreach ($data['headers'] as $k => $v) {
             $request->setHeader($k, $v);
         }
     }
     if (!empty($data['body']) && method_exists($request, 'setBody')) {
         $request->setBody(json_encode($data['body']));
     }
     $debug = '#### REQUEST ####' . PHP_EOL;
     $debug .= $request->getRawHeaders();
     Terminus::getLogger()->debug('Headers: {headers}', array('headers' => $debug));
     if (isset($data['body'])) {
         Terminus::getLogger()->debug('Body: {body}', array('body' => $data['body']));
     }
     $response = $request->send();
     return $response;
 }
开发者ID:blueprintmrk,项目名称:cli,代码行数:42,代码来源:Request.php

示例12: __construct

 /**
  * @param Client $client
  */
 public function __construct(Client $client = null)
 {
     if (empty($client)) {
         $client = new Client();
         $client->setUserAgent(DEFAULT_USER_AGENT);
     }
     $this->client = $client;
 }
开发者ID:yuri-sagalovich,项目名称:nextcaller-php-api,代码行数:11,代码来源:NextCallerBrowser.php

示例13: testServerParamsAreRecorded

 public function testServerParamsAreRecorded()
 {
     $this->client->setUserAgent('CUSTOM UA')->get('/foo')->setAuth('username', 'password')->setProtocolVersion('1.0')->send();
     $latestRequest = unserialize($this->client->get('/_request/latest')->send()->getBody());
     $this->assertSame(HTTP_MOCK_HOST, $latestRequest['server']['SERVER_NAME']);
     $this->assertSame(HTTP_MOCK_PORT, $latestRequest['server']['SERVER_PORT']);
     $this->assertSame('username', $latestRequest['server']['PHP_AUTH_USER']);
     $this->assertSame('password', $latestRequest['server']['PHP_AUTH_PW']);
     $this->assertSame('HTTP/1.0', $latestRequest['server']['SERVER_PROTOCOL']);
     $this->assertSame('CUSTOM UA', $latestRequest['server']['HTTP_USER_AGENT']);
 }
开发者ID:internations,项目名称:http-mock,代码行数:11,代码来源:AppIntegrationTest.php

示例14: testShouldInterceptGuzzleLibrary

 public function testShouldInterceptGuzzleLibrary()
 {
     VCR::configure()->enableLibraryHooks(array('curl'));
     VCR::turnOn();
     VCR::insertCassette('unittest_guzzle_test');
     $client = new Client();
     $client->setUserAgent(false);
     $response = $client->post('http://example.com')->send();
     $this->assertEquals('This is a guzzle test dummy.', (string) $response->getBody(), 'Guzzle call was not intercepted.');
     VCR::eject();
     VCR::turnOff();
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:12,代码来源:VCRTest.php

示例15: __construct

 /**
  * Inject Guzzle in this test class
  * And set up the given client for use on
  * Damn Vulnerable Web Application... A vulnerable application
  * without API...
  * Difficulty resided in finding the way of using
  * cookies and correct documentation for all methods.
  */
 public function __construct()
 {
     parent::__construct();
     //prepare a cookie jar
     $jar = new ArrayCookieJar();
     $cookiePlugin = new CookiePlugin($jar);
     //get a guzzle instance
     $this->_dvwa_guzzle = new Client();
     $this->_dvwa_guzzle->setBaseUrl($this->DVWA_URL);
     $this->_dvwa_guzzle->setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
     $this->_dvwa_guzzle->addSubscriber($cookiePlugin);
     //first request/response exchange to get CSRF token
     $request = $this->_dvwa_guzzle->get('login.php', null, ["allow_redirects" => false]);
     $response = $request->send();
     $str = $response->getBody();
     preg_match($this->USER_TOKEN_REGEX, $str, $matches);
     $user_token = $matches[1];
     //second exchange to login
     $request = $this->_dvwa_guzzle->createRequest('POST', 'login.php', null, ['username' => 'admin', 'password' => 'password', 'Login' => 'Login', 'user_token' => $user_token], ["allow_redirects" => true]);
     $request->send();
 }
开发者ID:haterecoil,项目名称:zerowing,代码行数:29,代码来源:PentestControllerTest.php


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