本文整理汇总了PHP中Guzzle\Http\Client::setDefaultOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setDefaultOption方法的具体用法?PHP Client::setDefaultOption怎么用?PHP Client::setDefaultOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::setDefaultOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
/**
* Fetch data from the Marketplace API
*
* @param $url
* @param $method
* @param null $body
* @param array $headers
* @return array|bool
*/
public function fetch($url, $method, $body = null, $headers = array())
{
if (!empty($headers)) {
$this->httpClient->setDefaultOption('headers', $headers);
}
switch ($method) {
case 'put':
case 'post':
$request = $this->httpClient->{$method}($url, $headers, $body);
break;
case 'delete':
case 'get':
$request = $this->httpClient->{$method}($url, $headers);
break;
default:
return false;
break;
}
try {
$response = $request->send();
} catch (\Exception $e) {
return false;
}
return array('status_code' => $response->getStatusCode(), 'body' => $response->json());
}
示例2: _fetchById
protected function _fetchById($id, $options)
{
$settings = craft()->plugins->getPlugin('weather')->getSettings();
try {
$client = new Client('http://api.openweathermap.org');
foreach ($options as $key => $value) {
$client->setDefaultOption("query/{$key}", $value);
}
if (isset($settings->apiKey) && strlen($settings->apiKey) > 0) {
$client->setDefaultOption('query/APPID', $settings->apiKey);
}
$client->setDefaultOption('query/id', $id);
$request = $client->get('/data/2.5/weather', array('$e'));
$response = $request->send();
} catch (CurlException $e) {
WeatherPlugin::log("Connection error to Open Weather Maps API", LogLevel::Error);
return false;
}
if ($response->isSuccessful()) {
$data = $response->json();
if ($data['cod'] == 200) {
return $data;
} else {
WeatherPlugin::log("Error: {$data['message']}", LogLevel::Error);
return false;
}
}
}
示例3: array
/**
* Constructor.
*
* @param \stdClass $credentials
* An object with the following properties:
* - username: Your Browserstack API username.
* - password: Your Browserstack API key.
*
* @throws \InvalidArgumentException
*/
function __construct($credentials)
{
if (empty($credentials->username) || empty($credentials->password)) {
throw new \InvalidArgumentException('Username and password parameters are required.');
}
$this->client = new \Guzzle\Http\Client('http://www.browserstack.com/screenshots');
$this->client->setDefaultOption('auth', array($credentials->username, $credentials->password, 'Basic'));
}
示例4: getHttpClient
/**
* @return Client
*/
public function getHttpClient()
{
if (!$this->client instanceof Client) {
$this->client = new Client($this->uri);
$this->client->setDefaultOption('headers/Api-Key', $this->apiKey);
}
return $this->client;
}
示例5: __construct
/**
*
*/
public function __construct()
{
// init the client
$this->client = new Client();
$this->client->setDefaultOption('auth', [env('JIRA_USERNAME'), env('JIRA_PASSWORD')]);
$this->client->setDefaultOption('verify', false);
$this->parser = new JiraParser(config('jira.BaseUrl'));
}
示例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: __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);
}
示例8: setUp
public function setUp()
{
parent::setUp();
$this->client = new Client($this->base_url, array('ssl.certificate_authority' => 'system'));
$this->xml_client = new Client($this->base_url, array('ssl.certificate_authority' => 'system'));
$this->client->setDefaultOption('headers/Accept', 'application/json');
$this->client->setDefaultOption('headers/Content-Type', 'application/json');
$this->xml_client->setDefaultOption('headers/Accept', 'application/xml');
$this->xml_client->setDefaultOption('headers/Content-Type', 'application/xml; charset=UTF8');
}
示例9: _initialize
public function _initialize()
{
$url = trim($this->config['url'], '/') . ':' . $this->config['port'];
$this->mailcatcher = new \Guzzle\Http\Client($url);
if (isset($this->config['guzzleRequestOptions'])) {
foreach ($this->config['guzzleRequestOptions'] as $option => $value) {
$this->mailcatcher->setDefaultOption($option, $value);
}
}
}
示例10: client
public function client()
{
if ($this->client) {
return $this->client;
}
$this->client = new Client($this->apiUrl);
$this->client->setDefaultOption('headers/Accept', 'application/json');
$this->client->setDefaultOption('headers/Content-Type', 'application/json');
$this->authenticate();
return $this->client;
}
示例11: setUp
public function setUp() {
parent::setUp();
$this->client = new Client($this->base_url);
$this->xml_client = new Client($this->base_url);
$this->client->setDefaultOption('headers/Accept', 'application/json');
$this->client->setDefaultOption('headers/Content-Type', 'application/json');
$this->xml_client->setDefaultOption('headers/Accept', 'application/xml');
$this->xml_client->setDefaultOption('headers/Content-Type', 'application/xml; charset=UTF8');
}
示例12: __construct
/**
* @param $uri
* @param $username
* @param $password
*/
public function __construct($uri, $username = "", $password = "")
{
error_log("{$username} {$password}");
$this->uri = $uri;
$this->username = $username;
$this->password = $password;
$this->logger = new \Psr\Log\NullLogger();
$client = new Http\Client($uri);
$client->setDefaultOption('auth', array($username, $password, 'Basic'));
$client->setDefaultOption('timeout', 5);
$client->setDefaultOption('connect_timeout', 1);
$this->setClient($client);
}
示例13: makeRequest
/**
* Makes the request to the server.
*
* @param string $server
* @param string $service The rest service to access e.g. /connections/communities/all
* @param string $method GET, POST or PUT
* @param string $body
* @param string $headers
*/
public function makeRequest($server, $service, $method, $options, $body = null, $headers = null, $endpointName = "connections")
{
$store = SBTCredentialStore::getInstance();
$settings = new SBTSettings();
$token = $store->getToken($endpointName);
$response = null;
$client = new Client($server);
$client->setDefaultOption('verify', false);
// If global username and password is set, then use it; otherwise use user-specific credentials
if ($settings->getBasicAuthMethod($endpointName) == 'global') {
$user = $settings->getBasicAuthUsername($endpointName);
$password = $settings->getBasicAuthPassword($endpointName);
} else {
$user = $store->getBasicAuthUsername($endpointName);
$password = $store->getBasicAuthPassword($endpointName);
}
try {
$request = $client->createRequest($method, $service, $headers, $body, $options);
if ($settings->forceSSLTrust($endpointName)) {
$request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
$request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
}
if ($method == 'POST' && isset($_FILES['file']['tmp_name'])) {
$request->addPostFile('file', $_FILES['file']['tmp_name']);
}
$request->setAuth($user, $password);
$response = $request->send();
} catch (Guzzle\Http\Exception\BadResponseException $e) {
$response = $e->getResponse();
}
return $response;
}
示例14: run
public function run($data, $ips)
{
if ($data && $ips and is_array($ips)) {
foreach ($ips as $ip) {
$client = new Client('http://' . $ip);
$client->setDefaultOption('headers', ['Content-type' => 'application/json']);
$client->setDefaultOption('exceptions', false);
$client->setDefaultOption('timeout', 20);
$client->setDefaultOption('connecttimeout', 0);
$client->setDefaultOption('debug', false);
$request = $client->post("/", [], []);
$request->setBody($data);
$request->send();
}
}
}
示例15: buildRequestD
public static function buildRequestD($pageId, $act, $servlet, $timeStamp)
{
ValidateFunc::checkNotNull($pageId, "Page id can't be null");
$client = new Client(CommonInfo::$DOMAIN . $servlet);
$params = array(CommonInfo::$URL_ACT => $act, CommonInfo::$URL_PAGEID => $pageId, CommonInfo::$URL_TIMESTAMP => $timeStamp);
$client->setDefaultOption('query', $params);
return $client;
}