本文整理汇总了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;
}
示例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()));
}
示例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;
}
示例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) {
};
}
示例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);
}
示例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);
}
示例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']);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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']);
}
示例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();
}
示例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();
}