本文整理汇总了PHP中Guzzle\Http\Client::setBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setBaseUrl方法的具体用法?PHP Client::setBaseUrl怎么用?PHP Client::setBaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::setBaseUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setHost
public function setHost($host)
{
$this->_host = $host;
if ($this->_connection) {
$this->_connection->setBaseUrl($host);
}
return $this;
}
示例2: __construct
/**
* Creates a Salesforce REST API client that uses username-password authentication
* @param AuthenticationInterface $authentication
* @param Http\Client $guzzle
* @param string $apiRegion The region to use for the Salesforce API. i.e. na5 or cs30
* @param string $apiVersion The version of the API to use. i.e. v31.0
* @param LoggerInterface $log
*/
public function __construct(AuthenticationInterface $authentication, Http\Client $guzzle, $apiRegion, $apiVersion = 'v31.0', LoggerInterface $log = null)
{
$this->apiBaseUrl = str_replace(array('{region}', '{version}'), array($apiRegion, $apiVersion), static::SALESFORCE_API_URL_PATTERN);
$this->log = $log ?: new NullLogger();
$this->authentication = $authentication;
$this->guzzle = $guzzle;
$this->guzzle->setBaseUrl($this->apiBaseUrl);
}
示例3: __construct
public function __construct($clientId, $clientSecret, $username, $password, $securityToken, Http\Client $guzzle, LoggerInterface $log = null, $loginApiUrl = "https://login.salesforce.com/services/")
{
$this->log = $log ?: new NullLogger();
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->username = $username;
$this->password = $password;
$this->securityToken = $securityToken;
$this->guzzle = $guzzle;
$this->guzzle->setBaseUrl($loginApiUrl);
}
示例4: testClientReturnsValidBaseUrls
public function testClientReturnsValidBaseUrls()
{
$client = new Client('http://www.{foo}.{data}/', array('data' => '123', 'foo' => 'bar'));
$this->assertEquals('http://www.bar.123/', $client->getBaseUrl());
$client->setBaseUrl('http://www.google.com/');
$this->assertEquals('http://www.google.com/', $client->getBaseUrl());
}
示例5: __construct
/**
* Constructor requires final url endpoint to send request to as
* first parameter. Optional second argument is a client object of type
* Guzzle\Http\Client.
*
*
* @param string $baseUrl Host to make requests to e.g. https://www.lush.co.uk
* @param \Guzzle\Http\Client $client Instance of Guzzle client object to use.
* @param bool $debug If set to true then debug messages will be emitted by the underlying Guzzle client
*/
public function __construct($baseUrl, \Guzzle\Http\Client $client, $debug = false)
{
$this->baseUrl = $baseUrl;
$client->setBaseUrl($this->baseUrl);
$this->client = $client;
$this->debug = (bool) $debug;
}
示例6: call
/**
* Returns the response body using the PHP cURL Extension
* @param Config $config
* @param string $request_path Request Path/URI
* @throws HttpException Unable to query server
*/
public function call(Config $config, $request_path)
{
// Setup
$this->guzzle->setBaseUrl('http://' . $config->getCloudHost());
$options = array('auth' => explode(':', $config->api_key, 2), 'timeout' => $this->timeout_ms / 1000, 'connect_timeout' => $this->timeout_ms / 1000, 'proxy' => $this->proxy);
// Compression
if ($this->use_compression === true) {
$this->request_headers['Accept-Encoding'] = 'gzip';
}
// Execute
try {
$request = $this->guzzle->get($request_path, $this->request_headers, $options);
$response = $request->send();
} catch (BadResponseException $e) {
return $this->processGuzzleResponse($e->getResponse());
} catch (\Exception $e) {
throw new HttpException("Unable to contact server: Guzzle Error: " . $e->getMessage(), null, $e);
}
return $this->processGuzzleResponse($response);
}
示例7: __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();
}
示例8: createRequest
/**
* Function to create a Guzzle HTTP request
*
* @param string $baseUri The protocol + host
* @param string $path The URI path after the host
* @param string $httpMethod The HTTP method to use for the request (GET, PUT, POST, DELTE etc.)
* @param array $requestHeaders Any additional headers for the request
* @param string $httpMethodParam Post parameter to set with a string that
* contains the HTTP method type sent with a POST
* @return RequestManager
*/
public function createRequest($baseUri, $path, $httpMethod = 'GET', $requestHeaders = array(), $httpMethodParam = null)
{
$this->client->setBaseUrl($baseUri);
if (!in_array(strtolower($httpMethod), array('get', 'put', 'post', 'patch', 'delete', 'head'))) {
throw new Exception("Invalid HTTP method");
}
$method = strtolower($httpMethod);
$method = $method == 'patch' ? 'put' : $method;
//override patch calls with put
if ($httpMethodParam != null && in_array($method, array('put', 'post', 'patch', 'delete'))) {
$this->request = $this->client->post($path);
$this->request->setPostField($httpMethodParam, strtoupper($method));
} else {
$this->request = $this->client->{$method}($path);
}
//set any additional headers on the request
$this->setHeaders($requestHeaders);
//setup how we get data back (xml, json etc)
$this->setTransportLanguage();
return $this->request;
}
示例9: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('neo4j.curl', function ($app) {
$curl = new Client();
$curl->setBaseUrl($app['config']->get('neo4j.base_url'));
return $curl;
});
$this->registerCypher();
$this->registerIndex();
$this->app->singleton('neo4j', function ($app) {
return new Neo4jClient($app['neo4j.cypher'], $app['neo4j.index']);
});
}
示例10: createClient
/**
* @param string $baseUrl
* @param ConsumerCredentials $consumerCredentials
* @param TokenCredentials $tokenCredentials
*
* @return Client
*/
public function createClient($baseUrl, ConsumerCredentials $consumerCredentials, TokenCredentials $tokenCredentials = null)
{
$oAuthConfig = array('consumer_key' => $consumerCredentials->getKey(), 'consumer_secret' => $consumerCredentials->getSecret());
if ($tokenCredentials instanceof TokenCredentials) {
$oAuthConfig += array('token' => $tokenCredentials->getToken(), 'token_secret' => $tokenCredentials->getSecret());
}
$oAuth = new OAuth($oAuthConfig);
$requestFactory = new JavaHttpRequestFactory();
$client = new Client();
$client->setBaseUrl($baseUrl)->addSubscriber($oAuth)->setRequestFactory($requestFactory);
foreach ($this->subscribers as $subscriber) {
$client->addSubscriber($subscriber);
}
return $client;
}
示例11: getDeleteResponseFromEndpoint
/**
* @param string $queryString
* @param AbstractEntity $entity
* @return \Guzzle\http\Message\Response
* @throws \Searchperience\Common\Http\Exception\EntityNotFoundException
* @throws \Searchperience\Common\Http\Exception\MethodNotAllowedException
* @throws \Searchperience\Common\Http\Exception\ForbiddenException
* @throws \Searchperience\Common\Http\Exception\ClientErrorResponseException
* @throws \Searchperience\Common\Exception\RuntimeException
* @throws \Searchperience\Common\Http\Exception\ServerErrorResponseException
* @throws \Searchperience\Common\Http\Exception\UnauthorizedException
* @throws \Searchperience\Common\Http\Exception\InternalServerErrorException
* @throws \Searchperience\Common\Http\Exception\RequestEntityTooLargeException
*/
protected function getDeleteResponseFromEndpoint($queryString = '', $entity = NULL)
{
try {
$postArray = $entity !== NULL ? $this->buildRequestArray($entity) : array();
/** @var $response \Guzzle\http\Message\Response */
$response = $this->restClient->setBaseUrl($this->baseUrl)->delete('/{customerKey}/' . $this->endpoint . $queryString, NULL, $postArray)->setAuth($this->username, $this->password)->send();
} catch (\Guzzle\Http\Exception\ClientErrorResponseException $exception) {
$this->transformStatusCodeToClientErrorResponseException($exception);
} catch (\Guzzle\Http\Exception\ServerErrorResponseException $exception) {
$this->transformStatusCodeToServerErrorResponseException($exception);
} catch (\Exception $exception) {
throw new \Searchperience\Common\Exception\RuntimeException('Unknown error occurred; Please check parent exception for more details.', 1353579284, $exception);
}
return $response;
}
示例12: search
/**
* @return SearchResultDto
* @throws \Guzzle\Http\Exception\BadResponseException
*/
public function search()
{
$searchUrl = $this->prepareSearchUrl();
$response = $this->guzzleClient->setBaseUrl($this->prepareSearchUrl())->get()->send();
$responseBody = substr($response->getBody(true), 62, -2);
if (!($responseDecoded = json_decode($responseBody))) {
throw new BadResponseException('Status code ' . $response->getStatusCode() . ': ' . strip_tags($response->getBody(true)));
}
if ($responseDecoded->status == 'error') {
$errorMessage = [];
foreach ($responseDecoded->errors as $error) {
$errorMessage[] = $error->reason . '. ' . $error->message . '. ' . $error->detailed_message;
}
throw new BadResponseException(implode(PHP_EOL, $errorMessage));
}
return $this->createDto($responseDecoded, $searchUrl);
}
示例13: __construct
public function __construct($guzzleClientSvc, $accessToken)
{
$this->guzzleClient = $guzzleClientSvc;
$this->accessToken = $accessToken;
$this->guzzleClient->setBaseUrl(self::CONTENTFUL_BASE_URL);
}
示例14: restoreBaseUrl
/**
* Restores the base URL in $client after a cal to setBaseUrl().
*/
protected function restoreBaseUrl()
{
$this->client->setBaseUrl($this->cachedBaseUrl);
}
示例15: setRequestContext
/**
* @param \Piece\Questetra\Core\RequestContext $requestContext
*/
public function setRequestContext(RequestContext $requestContext)
{
$this->requestContext = $requestContext;
$this->httpClient->setBaseUrl($this->requestContext->getContextRoot());
}