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


PHP Client::setOptions方法代码示例

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


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

示例1: sendRequest

 /**
  * {@inheritdoc}
  */
 public function sendRequest(RequestInterface $request)
 {
     $request = $this->sanitizeRequest($request);
     $headers = new Headers();
     foreach ($request->getHeaders() as $key => $value) {
         $headers->addHeader(new GenericHeader($key, $request->getHeaderLine($key)));
     }
     $zendRequest = new Request();
     $zendRequest->setMethod($request->getMethod());
     $zendRequest->setUri((string) $request->getUri());
     $zendRequest->setHeaders($headers);
     $zendRequest->setContent($request->getBody()->getContents());
     $options = ['httpversion' => $request->getProtocolVersion()];
     if (extension_loaded('curl')) {
         $options['curloptions'] = [CURLOPT_HTTP_VERSION => $this->getProtocolVersion($request->getProtocolVersion())];
     }
     $this->client->setOptions($options);
     if ($this->client->getAdapter() instanceof ZendClient\Adapter\Curl && $request->getMethod()) {
         $request = $request->withHeader('Content-Length', '0');
     }
     try {
         $zendResponse = $this->client->send($zendRequest);
     } catch (RuntimeException $exception) {
         throw new NetworkException($exception->getMessage(), $request, $exception);
     }
     return $this->responseFactory->createResponse($zendResponse->getStatusCode(), $zendResponse->getReasonPhrase(), $zendResponse->getHeaders()->toArray(), $zendResponse->getContent(), $zendResponse->getVersion());
 }
开发者ID:php-http,项目名称:zend-adapter,代码行数:30,代码来源:Client.php

示例2: downloadFromJotForm

 /**
  *
  * @param string $jotFormUrl        	
  * @throws UnableToRetrieveJotFormFile
  * @return $localFilePath
  */
 public function downloadFromJotForm($jotFormUrl, $password)
 {
     $client = new Client();
     $client->setUri($jotFormUrl);
     $client->setOptions(array('maxredirects' => 2, 'timeout' => 30));
     // Set Certification Path when https is used - does not work (yet)
     if (strpos($jotFormUrl, 'https:') === 0) {
         $client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE)));
     }
     // will use temp file
     $client->setStream();
     // Password, if set
     if (!empty($password)) {
         $client->setMethod(Request::METHOD_POST);
         $client->setParameterPost(array('passKey' => $password));
     }
     $response = $client->send();
     if ($response->getStatusCode() != 200) {
         throw new UnableToRetrieveJotFormFile('Wront StatusCode: ' . $response->getStatusCode() . ' (StatusCode=200 expected)');
     }
     // Copy StreamInput
     $tmpName = tempnam('/tmp', 'jotFormReport_');
     copy($response->getStreamName(), $tmpName);
     // Add to delete late
     $this->downloads[] = $tmpName;
     return $tmpName;
 }
开发者ID:stevenbuehner,项目名称:import-jot-form,代码行数:33,代码来源:JotFormDownloadHelper.php

示例3: getHttpClient

 /**
  * Get HTTP Client.
  *
  * @return Zend\Http\Client
  */
 public function getHttpClient()
 {
     if (!$this->httpClient) {
         $this->httpClient = new HttpClient();
         $this->httpClient->setOptions(array('strictredirects' => true));
     }
     return $this->httpClient;
 }
开发者ID:boboldehampsink,项目名称:ZendService_Microsoft_Wns,代码行数:13,代码来源:Client.php

示例4: proceed

 /**
  * @param Request $request
  * @return Response
  */
 protected function proceed(Http $httpUri, Request $request)
 {
     $httpUri = $httpUri->parse($this->moduleOptions->getApiUrl() . $httpUri->toString());
     $request->setUri($httpUri);
     $this->httpClient->setAuth($this->moduleOptions->getUserName(), $this->moduleOptions->getPassword());
     $this->httpClient->setOptions(array('sslverifypeer' => false));
     return $this->httpClient->send($request);
 }
开发者ID:spalax,项目名称:zf2-client-moysklad,代码行数:12,代码来源:GenericTransport.php

示例5: getClient

 /**
  * Клиент для работы с HTTP Api.
  *
  * @return Client
  */
 public function getClient()
 {
     if (!$this->client) {
         $this->client = new Client();
         $this->client->setOptions(array('sslverifypeer' => false));
     }
     return $this->client;
 }
开发者ID:advsm,项目名称:masterfolio,代码行数:13,代码来源:Api.php

示例6: __construct

 public function __construct($config)
 {
     if (!isset($config['yql_base_url'])) {
         throw new \InvalidArgumentException('Missing yql_base_url in config');
     }
     $this->client = new Client();
     $this->client->setUri($config['yql_base_url']);
     $this->client->setOptions(array('maxredirects' => 0, 'timeout' => 10));
 }
开发者ID:machek,项目名称:mmyql,代码行数:9,代码来源:ServiceYQL.php

示例7: createService

 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $client = new Client();
     $client->setOptions($config['oauth2']['httpClient']);
     return $client;
 }
开发者ID:coogle,项目名称:oauth2,代码行数:7,代码来源:ClientFactory.php

示例8: send

 /**
  * @param MessageInterface|Message $message
  * @return mixed|void
  * @throws RuntimeException
  */
 public function send(MessageInterface $message)
 {
     $config = $this->getSenderOptions();
     $serviceURL = "http://letsads.com/api";
     $body = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request></request>');
     $auth = $body->addChild('auth');
     $auth->addChild('login', $config->getUsername());
     $auth->addChild('password', $config->getPassword());
     $messageXML = $body->addChild('message');
     $messageXML->addChild('from', $config->getSender());
     $messageXML->addChild('text', $message->getMessage());
     $messageXML->addChild('recipient', $message->getRecipient());
     $client = new Client();
     $client->setMethod(Request::METHOD_POST);
     $client->setUri($serviceURL);
     $client->setRawBody($body->asXML());
     $client->setOptions(['sslverifypeer' => false, 'sslallowselfsigned' => true]);
     try {
         $response = $client->send();
     } catch (Client\Exception\RuntimeException $e) {
         throw new RuntimeException("Failed to send sms", null, $e);
     }
     try {
         $responseXML = new \SimpleXMLElement($response->getBody());
     } catch (\Exception $e) {
         throw new RuntimeException("Cannot parse response", null, $e);
     }
     if ($responseXML->name === 'error') {
         throw new RuntimeException("LetsAds return error (" . $responseXML->description . ')');
     }
 }
开发者ID:andreylis,项目名称:zf2-sms-adapters,代码行数:36,代码来源:LetsAdsAdapter.php

示例9: configureClient

 /**
  * {@inheritdoc}
  * @see \InoPerunApi\Client\Authenticator\ClientAuthenticatorInterface::configureClient()
  */
 public function configureClient(Http\Client $httpClient)
 {
     $keyFile = $this->getOption(self::OPT_KEY_FILE, null, true);
     $crtFile = $this->getOption(self::OPT_CRT_FILE, null, true);
     $keyPass = $this->getOption(self::OPT_KEY_PASS);
     $httpClient->setOptions(array('curloptions' => array(CURLOPT_SSLKEY => $keyFile, CURLOPT_SSLCERT => $crtFile, CURLOPT_SSLKEYPASSWD => $keyPass)));
 }
开发者ID:ivan-novakov,项目名称:php-perun-api,代码行数:11,代码来源:ClientCertificate.php

示例10: enableRequestDebugLogging

 /**
  * This method enables logging of requests by changing the
  * Zend_Http_Client_Adapter used for performing the requests.
  * NOTE: This will not work if you have customized the adapter
  * already to use a proxy server or other interface.
  *
  * @param $logfile The logfile to use when logging the requests
  */
 public function enableRequestDebugLogging($logfile)
 {
     $this->_httpClient->setOptions(array(
         'adapter' => 'Zend\GData\App\LoggingHttpClientAdapterSocket',
         'logfile' => $logfile
         ));
 }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:15,代码来源:App.php

示例11: getServiceConfig

 public function getServiceConfig()
 {
     return array('factories' => array('Changelog\\XmlRpc\\Client' => function ($services) {
         $config = $services->get('Config');
         if (!isset($config['changelog'])) {
             throw new RuntimeException('Expecting a "changelog" key in configuration; none found');
         }
         $config = $config['changelog'];
         if (!isset($config['jira']) || !is_array($config['jira'])) {
             throw new RuntimeException('Expecting an array of JIRA credentials in "changelog" configuration; none found');
         }
         $jiraUrl = isset($config['jira']['url']) ? $config['jira']['url'] : 'http://framework.zend.com/issues/rpc/xmlrpc';
         $cxn = new XmlRpcClient($jiraUrl);
         $client = $cxn->getProxy('jira1');
         return $client;
     }, 'Changelog\\Jira\\Auth' => function ($services) {
         $config = $services->get('Config');
         if (!isset($config['changelog'])) {
             throw new RuntimeException('Expecting a "changelog" key in configuration; none found');
         }
         $config = $config['changelog'];
         if (!isset($config['jira']) || !is_array($config['jira'])) {
             throw new RuntimeException('Expecting an array of JIRA credentials in "changelog" configuration; none found');
         }
         $jiraCredentials = $config['jira'];
         $client = $services->get('Changelog\\XmlRpc\\Client');
         $auth = $client->login($jiraCredentials['username'], $jiraCredentials['password']);
         return $auth;
     }, 'Changelog\\Http\\Client' => function ($services) {
         $client = new HttpClient();
         $client->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'keepalive' => true, 'timeout' => 10));
         return $client;
     }));
 }
开发者ID:vrkansagara,项目名称:zf-web,代码行数:34,代码来源:Module.php

示例12: getHttpClient

 /**
  *
  * @param string $uri
  * @return \Zend\Http\Client
  */
 protected function getHttpClient($uri)
 {
     $client = new Client();
     $client->setUri($uri);
     $client->setOptions(['maxredirects' => 5, 'timeout' => 30])->setHeaders(['Accept-encoding' => 'gzip,deflate', 'X-Powered-By: OClient']);
     return $client;
 }
开发者ID:belgattitude,项目名称:openstore-client,代码行数:12,代码来源:BaseService.php

示例13: configureClientConfig

 /**
  * Configures the client configs
  *
  * @param array $configs the http client configuration array
  *
  * @return mixed
  */
 public function configureClientConfig(array $configs)
 {
     // We set the http client object
     $this->client->setOptions($configs);
     // We return the configured http client object
     return $this->client;
 }
开发者ID:mslib,项目名称:remote-host,代码行数:14,代码来源:AbstractHostApi.php

示例14: getServiceConfig

 public function getServiceConfig()
 {
     return array('factories' => array('Search\\GoogleCustomSearch' => function ($services) {
         $config = $services->get('Config');
         if (!isset($config['search'])) {
             throw new ServiceNotFoundException(sprintf('Unable to create %s; missing configuration key "search", with subkeys "apikey" and "custom_search_identifier"', __NAMESPACE__ . '\\GoogleCustomSearch'));
         }
         $config = $config['search'];
         if (!isset($config['apikey']) || !is_string($config['apikey'])) {
             throw new ServiceNotFoundException(sprintf('Unable to create %s; missing subkey "apikey"', __NAMESPACE__ . '\\GoogleCustomSearch'));
         }
         if (!isset($config['custom_search_identifier']) || !is_string($config['custom_search_identifier'])) {
             throw new ServiceNotFoundException(sprintf('Unable to create %s; missing subkey "custom_search_identifier"', __NAMESPACE__ . '\\GoogleCustomSearch'));
         }
         $queryOptions = isset($config['query_options']) && is_array($config['query_options']) ? $config['query_options'] : array();
         $httpClientService = isset($config['http_client_service']) && is_string($config['http_client_service']) ? $config['http_client_service'] : false;
         if ($httpClientService && $services->has($httpClientService)) {
             $httpClient = $services->get($httpClientService);
         } else {
             $httpClient = new HttpClient();
             $httpClient->setOptions(array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'keepalive' => true, 'timeout' => 10));
         }
         $search = new GoogleCustomSearch($httpClient, $config['apikey'], $config['custom_search_identifier'], $queryOptions);
         if (isset($config['items_per_page'])) {
             $search->setItemsPerPage($config['items_per_page']);
         }
         return $search;
     }));
 }
开发者ID:Tony133,项目名称:zf-web,代码行数:29,代码来源:Module.php

示例15: getLatLng

 public static function getLatLng($address)
 {
     $latLng = [];
     try {
         $url = sprintf('http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false', $address);
         $client = new Client($url);
         $client->setAdapter(new Curl());
         $client->setMethod('GET');
         $client->setOptions(['curloptions' => [CURLOPT_HEADER => false]]);
         $response = $client->send();
         $body = $response->getBody();
         $result = Json\Json::decode($body, 1);
         $latLng = ['lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']];
         $isException = false;
     } catch (\Zend\Http\Exception\RuntimeException $e) {
         $isException = true;
     } catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) {
         $isException = true;
     } catch (Json\Exception\RuntimeException $e) {
         $isException = true;
     } catch (Json\Exception\RecursionException $e2) {
         $isException = true;
     } catch (Json\Exception\InvalidArgumentException $e3) {
         $isException = true;
     } catch (Json\Exception\BadMethodCallException $e4) {
         $isException = true;
     }
     if ($isException === true) {
         //código em caso de problemas no decode
     }
     return $latLng;
 }
开发者ID:armenio,项目名称:armenio-zf2-geolocation-module,代码行数:32,代码来源:GeoLocation.php


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