当前位置: 首页>>代码示例>>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;未经允许,请勿转载。