當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::setDefaultOption方法代碼示例

本文整理匯總了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());
 }
開發者ID:SourceCode,項目名稱:Marketplace.PHP,代碼行數:34,代碼來源:Connection.php

示例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;
         }
     }
 }
開發者ID:agencyleroy,項目名稱:craft-weather,代碼行數:28,代碼來源:WeatherService.php

示例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'));
 }
開發者ID:ksenzee,項目名稱:browserstack-screenshots-php,代碼行數:18,代碼來源:ScreenshotsClient.php

示例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;
 }
開發者ID:niborb,項目名稱:postcode-api-nu,代碼行數:11,代碼來源:DefaultClient.php

示例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'));
 }
開發者ID:ChristophJaecksF4H,項目名稱:tico_test,代碼行數:11,代碼來源:JiraAdapter.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: __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

示例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');
 }
開發者ID:pombredanne,項目名稱:tuleap,代碼行數:10,代碼來源:RestBase.php

示例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);
         }
     }
 }
開發者ID:davjand,項目名稱:codecept-symphonycms-db,代碼行數:10,代碼來源:EXAMPLE-mailcatcher.php

示例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;
 }
開發者ID:eMaurits,項目名稱:exact-php-client,代碼行數:11,代碼來源:Connection.php

示例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');
    }
開發者ID:rinodung,項目名稱:tuleap,代碼行數:11,代碼來源:RestBase.php

示例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);
 }
開發者ID:centraldesktop,項目名稱:php-jmx,代碼行數:18,代碼來源:Client.php

示例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;
 }
開發者ID:ItemConsulting,項目名稱:SocialSDK,代碼行數:41,代碼來源:SBTBasicAuthEndpoint.php

示例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();
         }
     }
 }
開發者ID:Nebo15,項目名稱:nebo15.warehouse,代碼行數:16,代碼來源:Deploy.php

示例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;
 }
開發者ID:zalopage,項目名稱:Zalo-Sdk-Php,代碼行數:8,代碼來源:ZaloSdkHelper.php


注:本文中的Guzzle\Http\Client::setDefaultOption方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。