本文整理匯總了PHP中Buzz\Browser::call方法的典型用法代碼示例。如果您正苦於以下問題:PHP Browser::call方法的具體用法?PHP Browser::call怎麽用?PHP Browser::call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Buzz\Browser
的用法示例。
在下文中一共展示了Browser::call方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: request
/**
*
* @param string $path Path (will be appended to the Base URL)
* @param array $params
* @param mixed $method
* @return \SimpleXMLElement
*/
protected function request($path, array $params = null, $method = RequestInterface::METHOD_GET)
{
// Full URL
$fullUrl = new Url($this->baseUrl . $path);
// Additional headers
$headers = array('User-Agent: ' . $this->getUserAgentString());
// Got data?
if ($method === RequestInterface::METHOD_GET) {
if ($params != null && count($params) > 0) {
$fullUrl = new Url($this->baseUrl . $path . '?' . http_build_query($params));
}
$response = $this->browser->get($fullUrl, $headers);
} else {
$response = $this->browser->call($fullUrl, $method, $headers, $params);
}
// Convert XML
$xml = @simplexml_load_string($response->getContent());
// Succesful?
if ($xml === false) {
throw new MollieException('Server did not respond with valid XML.');
}
// Error?
if ($xml->item != null && (string) $xml->item['type'] == 'error') {
throw new MollieException((string) $xml->item->message, intval($xml->item->errorcode));
}
return $xml;
}
示例2: execute
/**
* Executes a http request.
*
* @param Request $request The http request.
*
* @return Response The http response.
*/
public function execute(Request $request)
{
$method = $request->getMethod();
$endpoint = $request->getEndpoint();
$params = $request->getParams();
$headers = $request->getHeaders();
try {
if ($method === 'GET') {
$buzzResponse = $this->client->call($endpoint . '?' . http_build_query($params), $method, $headers, array());
} else {
$buzzRequest = new FormRequest();
$buzzRequest->fromUrl($endpoint);
$buzzRequest->setMethod($method);
$buzzRequest->setHeaders($headers);
foreach ($params as $key => $value) {
if ($value instanceof Image) {
$value = new FormUpload($value->getData());
}
$buzzRequest->setField($key, $value);
}
$buzzResponse = new BuzzResponse();
$this->client->send($buzzRequest, $buzzResponse);
}
} catch (RequestException $e) {
throw new Exception($e->getMessage());
}
return static::convertResponse($request, $buzzResponse);
}
示例3: send
/**
* Make a request against the FatSecret APIs.
*
* @param String $base_url
* @param array $params
* @param string $method
*
* @return \Buzz\Message\MessageInterface
*/
public function send($base_url, array $params = [], $method = 'GET')
{
if (!$this->isInitialized()) {
throw new \ErrorException("The consumer key and secret must be set first.");
}
$params = $this->parseParams($params);
$signature = $this->getSignature($base_url, $params, $method);
$params = array_merge($params, ['oauth_signature' => $signature]);
$api_url = $this->getAPIEndpoint($base_url, $method, $params);
return $this->client->call($api_url, $method, [], $params);
}
示例4: getContent
/**
* {@inheritDoc}
*/
public function getContent($url, $method = 'GET', array $headers = array(), $data = array())
{
if (is_array($data)) {
$data = $this->encodePostData($data);
}
try {
$response = $this->browser->call($url, $method, $headers, $data);
} catch (\Exception $e) {
return null;
}
return $response ? $response->getContent() : null;
}
示例5: call
/**
* @todo: should also resolve jsonrpc and jsonrpcs schemas.
*
* {@inheritdoc}
*/
public function call(Identity $identity, Request $request)
{
$url = $identity->getUrl(['https', 'http']);
$headers = $this->getEncodedHeaders();
$body = $this->getEncodedBody($request);
/** @var HttpResponse $response */
$response = $this->buzz->call($url, 'POST', $headers, $body);
return new Promise(function () use($response) {
$result = $this->getDecodedBody($response->getContent());
return new Response($result);
});
}
示例6: call
/**
* {@inheritdoc}
*/
public function call(LocationInterface $location, Request $request)
{
$headers = $this->getEncodedHeaders($location, $request);
$body = $this->getEncodedBody($request);
$url = $this->getRequestUrl($location);
/** @var HttpResponse $response */
$response = $this->buzz->call($url, 'POST', $headers, $body);
return new Response\Promise(function () use($response) {
$result = $this->getDecodedBody($response->getContent());
$headers = $this->getDecodedHeaders($response->getHeaders());
return new Response($result, $headers);
});
}
示例7: request
/**
* Prepare the curl request
*
* @param string $apiCall the API call function
* @param array $payload Parameters
* @return array
*/
public function request($method, $apiCall, $payload = [])
{
$url = rtrim($this->baseUrl . $apiCall, '/?');
$curl = $this->prepareCurl();
$browser = new Browser($curl);
$headers = ["Authorization" => "Bearer " . $this->token, "Content-type" => "application/json"];
$response = $browser->call($url, $method, $headers, json_encode($payload));
return $response->getContent();
}
示例8: iRequest
/**
* @When /^I request "([^"]*)"$/
* @param string $pageUrl
* @return void
* @throws \Exception
*/
public function iRequest($pageUrl)
{
$this->responseData = $this->responseDecodeException = null;
$this->responseIsJson = false;
if ($this->access_token) {
$this->headers['Authorization'] = 'Bearer ' . $this->access_token;
}
$this->client->call($this->processPageUrl($pageUrl), strtolower($this->requestMethod), $this->headers);
$this->response = $this->client->getLastResponse();
}
示例9: sendRequest
/**
* Sends a request.
*
* @param string $url The url.
* @param string $method The http method.
* @param array $headers The header.
* @param array $content The content.
*
* @throws \Widop\HttpAdapter\HttpAdapterException If an error occured.
*
* @return \Widop\HttpAdapter\HttpResponse The response.
*/
private function sendRequest($url, $method, array $headers = array(), array $content = array())
{
$this->browser->getClient()->setMaxRedirects($this->getMaxRedirects());
try {
$response = $this->browser->call($url, $method, $headers, $content);
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $e->getMessage());
}
return $this->createResponse($response->getStatusCode(), $url, $response->getHeaders(), $response->getContent());
}
示例10: purgeAll
/**
* Purges all content elements currently in cache.
*
* @return void
*/
public function purgeAll()
{
foreach ($this->purgeServers as $server) {
$this->prepareUserAuth($server);
$this->httpBrowser->call($server, 'PURGE', array('X-Location-Id' => '*'));
$client = $this->httpBrowser->getClient();
if ($client instanceof BatchClientInterface) {
$client->flush();
}
}
}
示例11: call
public function call($api_method, $http_method = RequestInterface::METHOD_GET, array $query_string = array(), $headers = array(), $content = '')
{
$url = sprintf('%s/%s/%s?%s', $this->api_endpoints[array_rand($this->api_endpoints)], self::API_PATH, $api_method, http_build_query($query_string));
$response = $this->client->call($url, $http_method, $headers, $content);
if ($response->isSuccessful()) {
$this->hasErrors($response->getContent());
return $response->getContent();
} else {
return $this->handleException($response);
}
}
示例12: call
/**
* @param \MatthiasNoback\MicrosoftTranslator\ApiCall\ApiCallInterface $apiCall
* @return mixed
*/
private function call(ApiCall\ApiCallInterface $apiCall)
{
$url = $apiCall->getUrl();
$method = $apiCall->getHttpMethod();
$headers = array('Authorization: Bearer ' . $this->getAccessToken(), 'Content-Type: text/xml');
$content = $apiCall->getRequestContent();
try {
$response = $this->browser->call($url, $method, $headers, $content);
} catch (\Exception $previous) {
throw new RequestFailedException(sprintf('Request failed: %s', $previous->getMessage()), null, $previous);
}
if (!$response->isSuccessful()) {
throw new RequestFailedException(sprintf('API call was not successful, %d: %s', $response->getStatusCode(), $response->getReasonPhrase()));
}
/* @var $response \Buzz\Message\Response */
$responseContent = $response->getContent();
return $apiCall->parseResponse($responseContent);
}
示例13: call
/**
* Sends a request.
*
* @param string $url The URL to call
* @param string $method The request method to use
* @param array $headers An array of request headers
* @param string $content The request content
* @param int $cacheLifetime serverside cache lifetime
*
* @return MessageInterface The response object
*/
public function call($url, $method, $headers = array(), $content = '', $cacheLifetime = null)
{
if ($this->cacher == null) {
return parent::call($url, $method, $headers, $content, $cacheLifetime);
}
$request = $this->factory->createRequest($method);
if (!$url instanceof Url) {
$url = new Url($url);
}
$url->applyToRequest($request);
$request->addHeaders($headers);
$request->setContent($content);
$this->data = $this->cacher->retrieveCachedResponse($request);
if (!$this->data) {
$this->fromCache = false;
$this->send($request);
$this->data = array('request' => parent::getLastRequest(), 'response' => parent::getLastResponse());
$this->cacher->cacheResponse($this->data['request'], $this->data['response'], $cacheLifetime);
}
return $this->data['response'];
}
示例14: __call
/**
* Perform an HTTP call
*
* $arguments is made of two arguments:
* - first: route (Example: "{token}/ticket/list/{root}")
* - second: parameters (Example: array("{root}" => "12", "key1" => "value2"), optionnal)
* => {token}/ticket/list/12?key1=value2
*
* @param string $method
* @param array $arguments
* @return array
*/
public function __call($method, $arguments)
{
// Check for arguments
if (empty($arguments)) {
throw new Exception("No arguments have been passed to ApiMapper::{$method}()");
}
// Extracts arguments (Note $parameters and $fields are optionnal)
$route = array_shift($arguments);
$parameters = empty($arguments) ? array() : array_shift($arguments);
$fields = empty($arguments) ? array() : array_shift($arguments);
// Fill route placeholders, and append query fields
$url = $this->buildUrl($route, $parameters);
// Add post field parameter providers
foreach ($this->postFieldsParameters as $fieldName => $field) {
$field = $field->lookup($route);
if ($field !== false) {
$fields[$fieldName] = $field;
}
}
// Load headers
$headers = array();
foreach ($this->headerProviders as $headerProvider) {
$header = $headerProvider->lookup($route);
if ($header !== false) {
$headers[] = $header;
}
}
// Perform the call
if (static::isSafeMethod($method)) {
$response = $this->browser->call($url, $method, $headers);
} else {
$response = $this->browser->submit($url, $fields, $method, $headers);
}
// Parse the content
$content = array("method" => strtoupper($method), "route" => $route, "url" => $url, "response" => $response, "parameters" => $parameters, "json" => json_decode($response->getContent(), true));
// Dispatch content to event listeners
$this->dispatch($content);
// Return the content
return $content;
}
示例15: doRequest
/**
* DoRequest
* @param string $url
* @param array $params
* @param string $httpMethod
* @param array $options
* @return array
*/
public function doRequest($url, array $parameters = array(), $httpMethod = 'GET', array $options = array())
{
if ($this->options['login']) {
switch ($this->options['auth_method']) {
case Client::AUTH_HTTP_PASSWORD:
$this->browser->getClient()->setOption(CURLOPT_USERPWD, $this->options['login '] . ':' . $this->options['secret']);
break;
case Client::AUTH_HTTP_TOKEN:
$this->browser->getClient()->setOption(CURLOPT_USERPWD, $this->options['login'] . '/token:' . $this->options['secret']);
break;
case Client::AUTH_URL_TOKEN:
default:
$parameters = array_merge(array('login' => $this->options['login'], 'token' => $this->options['secret']), $parameters);
break;
}
}
if (!empty($parameters)) {
$queryString = utf8_encode(http_build_query($parameters, '', '&'));
if ('GET' === $httpMethod) {
$url .= '?' . $queryString;
} else {
$this->browser->getClient()->setOption(CURLOPT_POST, true);
$this->browser->getClient()->setOption(CURLOPT_POSTFIELDS, $queryString);
}
}
$this->browser->getClient()->setOption(CURLOPT_URL, $url);
$this->browser->getClient()->setOption(CURLOPT_PORT, $this->options['http_port']);
$this->browser->getClient()->setOption(CURLOPT_USERAGENT, $this->options['user_agent']);
$this->browser->getClient()->setOption(CURLOPT_FOLLOWLOCATION, true);
$this->browser->getClient()->setOption(CURLOPT_RETURNTRANSFER, true);
$this->browser->getClient()->setOption(CURLOPT_SSL_VERIFYPEER, false);
$this->browser->getClient()->setOption(CURLOPT_TIMEOUT, $this->options['timeout']);
$response = $this->browser->call($url, $httpMethod, $this->headers, json_encode($parameters));
$this->checkApiLimit($response);
return array('response' => $response->getContent(), 'headers' => $response->getHeaders(), 'errorNumber' => '', 'errorMessage' => '');
}