本文整理汇总了PHP中Client::request方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::request方法的具体用法?PHP Client::request怎么用?PHP Client::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client
的用法示例。
在下文中一共展示了Client::request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logInAs
public function logInAs($username)
{
$crawler = $this->client->request('GET', '/login');
$form = $crawler->filter('button[type=submit]')->form();
$data = ['_username' => $username, '_password' => 'mypassword'];
$this->client->submit($form, $data);
}
示例2: doLogin
/**
* Do login with username
*
* @param string $username
*/
private function doLogin($username = 'admin')
{
$crawler = $this->client->request('GET', $this->getUrl('fos_user_security_login', array()));
$form = $crawler->selectButton('_submit')->form(array('_username' => $username, '_password' => 'qwerty'));
$this->client->submit($form);
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->client->followRedirects();
}
示例3: search
/**
* @param string $query
* @param array|null $args
*
* @return mixed
*
* @throws AlgoliaException
*/
public function search($query, $args = null)
{
if ($args === null) {
$args = array();
}
$args['query'] = $query;
return $this->client->request($this->context, 'POST', '/1/places/query', array(), array('params' => $this->client->buildQuery($args)), $this->context->readHostsArray, $this->context->connectTimeout, $this->context->searchTimeout);
}
示例4: request
public function request($method, $path, $data = null, $raw = false)
{
$start = microtime(true);
$response = $this->client->request($method, $path, $data, $raw);
$duration = microtime(true) - $start;
$this->requests[] = array('duration' => $duration, 'method' => $method, 'path' => rawurldecode($path), 'request' => $data, 'request_size' => strlen($data), 'response_status' => $response->status, 'response' => $response->body, 'response_headers' => $response->headers);
$this->totalDuration += $duration;
return $response;
}
示例5: run
public function run()
{
$urls = is_array($this->url) ? $this->url : [$this->url];
foreach ($urls as $url) {
$response = $this->client->request('GET', $url, ['headers' => ['User-Agent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)']]);
$contents[] = (string) $response->getBody();
}
return $contents;
}
示例6: request
public function request($url, array $parameters = array(), $method = Client::GET, array $headers = array(), array $options = array())
{
$key = $this->makeCacheKey($method, $url, $parameters);
if ($key) {
if ($this->cache->contains($key)) {
return $this->cache->fetch($key);
}
}
$result = $this->client->request($url, $parameters, $method, $headers, $options);
if ($key) {
$this->cache->save($key, $result, $this->lifetime);
}
return $result;
}
示例7: add
public function add(Request $request)
{
// Ask if we are supplying our own data or requesting it from the server
if ($request->has('remote') && ($request->remote = 'true')) {
$client = new Client();
$res = $client->request('GET', 'http://fsvaos.net/api/central/aircraft', ['query' => ['icao' => $request->icao]])->getBody();
// Add the airport to the database
$data = json_decode($res, true);
$aircraft = new Aircraft();
//return dd($data);
$aircraft->name = $data[0]['name'];
$aircraft->icao = $data[0]['icao'];
$aircraft->maxgw = $data[0]['maxgw'];
$aircraft->maxpax = $data[0]['maxpax'];
$aircraft->range = $data[0]['range'];
$aircraft->registration = $request->input('registration');
$aircraft->enabled = true;
$aircraft->hub = $request->input('hub');
$aircraft->save();
} else {
// insert manual entry system.
$aircraft = new Aircraft();
//return dd($data);
$aircraft->name = $request->input('name');
$aircraft->icao = $request->input('icao');
$aircraft->maxgw = $request->input('maxgw');
$aircraft->maxpax = $request->input('maxpax');
$aircraft->range = $request->input('range');
$aircraft->registration = $request->input('registration');
$aircraft->enabled = true;
$aircraft->hub = $request->input('hub');
$aircraft->save();
}
}
示例8: assertPutFails
/**
* assert that putting a fetched resource fails
*
* @param string $url url
* @param Client $client client to use
*
* @return void
*/
public function assertPutFails($url, $client)
{
$client->request('GET', $url);
$client->put($url, $client->getResults());
$response = $client->getResponse();
$this->assertEquals(405, $response->getStatusCode());
$this->assertEquals('GET, HEAD, OPTIONS', $response->headers->get('Allow'));
}
示例9: testSuccess
public function testSuccess()
{
$this->mockStaticMethod('\\MWHttpRequest', 'canMakeRequests', true);
$requestMock = $this->getMock('\\CurlHttpRequest', ['execute', 'getContent'], ['http://example.com'], '', false);
$requestMock->expects($this->once())->method('getContent')->willReturn('{}');
$this->mockStaticMethod('\\Http', 'request', $requestMock);
$client = new Client('http://example.com', 'id', 'secret');
$this->assertInternalType('object', $client->request('resource', [], [], []));
}
示例10: testDeleteReferenced
public function testDeleteReferenced()
{
$page = $this->documentManager->create('page');
$page->setStructureType('hotel_page');
$page->setTitle('Hotels page');
$page->setResourceSegment('/hotels');
$page->getStructure()->bind(['hotels' => [$this->hotel1->getUuid(), $this->hotel2->getUuid()]]);
$this->documentManager->persist($page, 'de', ['parent_path' => '/cmf/sulu_io/contents']);
$this->documentManager->flush();
$this->client->request('DELETE', '/snippets/' . $this->hotel1->getUuid() . '?_format=text');
$response = $this->client->getResponse();
$this->assertEquals(409, $response->getStatusCode());
}
示例11: request
/**
* Execute a request on this resource
*
* @param mixed $scope
* @param mixed $data
* @return mixed
*/
public function request($method, $scope = null, $data = null)
{
if (is_array($scope)) {
$data = $scope;
$scope = null;
}
$url = $scope ? $this->url . '/' . ltrim($scope, '/') : $this->url;
$result = self::$client->request($method, $url, $data);
if (!$scope && $result instanceof Resource) {
// TODO: how should POST be handled here?
foreach ($result->data() as $key => $value) {
self::offsetSet($key, $value);
}
}
return $scope ? $result : $this;
}
示例12: verify
/**
* Calls the reCAPTCHA siteverify API to verify whether the user passes
* CAPTCHA test.
*
* @param string $response The value of 'g-recaptcha-response' in the submitted form.
* @param string $remoteIp The end user's IP address.
* @return Response Response from the service.
*/
public function verify($response, $remoteIp = null)
{
// Discard empty solution submissions
if (empty($response)) {
$recaptchaResponse = new Response(false, array('missing-input-response'));
return $recaptchaResponse;
}
$q = [];
$q['secret'] = $this->secret;
$q['response'] = $response;
$q['remoteip'] = $remoteIp;
try {
$recaptchaResponse = $this->client->request("POST", null, ['form_params' => $q]);
} catch (\GuzzleHttp\Exception\RequestException $ex) {
$recaptchaResponse = $ex->getResponse();
}
return Response::fromJson($recaptchaResponse->getBody()->getContents());
}
示例13: browseFrom
/**
* @param string $query
* @param array|null $params
* @param $cursor
*
* @return mixed
*/
public function browseFrom($query, $params = null, $cursor = null)
{
if ($params === null) {
$params = [];
}
foreach ($params as $key => $value) {
if (gettype($value) == 'array') {
$params[$key] = json_encode($value);
}
}
if ($query != null) {
$params['query'] = $query;
}
if ($cursor != null) {
$params['cursor'] = $cursor;
}
return $this->client->request($this->context, 'GET', '/1/indexes/' . $this->urlIndexName . '/browse', $params, null, $this->context->readHostsArray, $this->context->connectTimeout, $this->context->readTimeout);
}
示例14: testRequestThrowsExpectedExceptionWhenResponseContainsErrorFlag
/**
* testRequestThrowsExpectedExceptionWhenResponseContainsErrorFlag
*
* @return void
* @covers \QafooLabs\RestClient\RemoteException
* @expectedException \QafooLabs\RestClient\RemoteException
*/
public function testRequestThrowsExpectedExceptionWhenResponseContainsErrorFlag()
{
$this->writeTestPath(array('error' => true, 'type' => 42, 'message' => 'A message'));
$client = new Client($this->server);
$client->request('GET', $this->path);
}
示例15: getEvents
/**
* @param string device
* @param string query
* @return json events
*/
public function getEvents($device, $query)
{
$response = $this->client->request('GET', 'http://api.thingsee.com/v2/events/' . Config::get('thingsee.' . $device . '') . $query, ['headers' => ['Authorization' => 'Bearer ' . $this->accountAuthToken]]);
return json_decode($response->getBody(), true);
}