本文整理汇总了PHP中Guzzle\Http\Message\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHandles404RevalidationResponses
public function testHandles404RevalidationResponses()
{
$request = new Request('GET', 'http://foo.com');
$request->setClient(new Client());
$badResponse = new Response(404, array(), 'Oh no!');
$badRequest = clone $request;
$badRequest->setResponse($badResponse, true);
$response = new Response(200, array(), 'foo');
$plugin = new CachePlugin();
$c = new ArrayCache();
$c->save('foo', array(200, array(), 'foo'));
$s = new DefaultCacheStorage(new DoctrineCacheAdapter($c));
$k = new CallbackCacheKeyProvider(function () {
return 'foo';
});
$rev = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\DefaultRevalidation')->setConstructorArgs(array($k, $s, $plugin))->setMethods(array('createRevalidationRequest'))->getMock();
$rev->expects($this->once())->method('createRevalidationRequest')->will($this->returnValue($badRequest));
try {
$rev->revalidate($request, $response);
$this->fail('Should have thrown an exception');
} catch (BadResponseException $e) {
$this->assertSame($badResponse, $e->getResponse());
$this->assertFalse($c->fetch('foo'));
}
}
示例2: setUp
public function setUp()
{
$this->client = $this->getSimpleMock('Guzzle\\Http\\ClientInterface');
$this->facade = new RequestCollectionFacade($this->client);
$this->request = new Request('GET', '/_request/last');
$this->request->setClient($this->client);
}
示例3: proceedResponse
/**
* @param Request $request
* @return array|null
* @throws BadResponseException
* @throws FormatException
*/
protected function proceedResponse(Request $request)
{
try {
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$response = $e->getResponse();
}
$body = $response->getBody(true);
if (empty($body) && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return null;
}
$result = json_decode($body, true);
if ($result === null) {
# When response is just a sting.
$result = $body;
}
if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return $result;
}
if (!$result || !$result['error']) {
throw new FormatException('Not valid error response', 3, null, $request, $response);
}
$message = $result['error']['message'];
$code = $result['error']['code'];
if ($response->getStatusCode() == 429) {
throw new RateLimitException($message, $code, null, $request, $response);
}
$e = new BadResponseException($message, $code, null, $request, $response);
$e->setError($result['error']);
throw $e;
}
示例4: generateRequest
protected function generateRequest($url, array $subProtocols, array $headers)
{
$headers = array_merge($this->defaultHeaders, $headers);
$headers['Sec-WebSocket-Key'] = $this->generateKey();
$request = new Request('GET', $url, $headers);
$scheme = strtolower($request->getScheme());
if (!in_array($scheme, ['ws', 'wss'])) {
throw new \InvalidArgumentException(sprintf('Cannot connect to invalid URL (%s)', $url));
}
$request->setScheme('HTTP');
if (!$request->getPort()) {
$request->setPort('wss' === $scheme ? 443 : 80);
} else {
$request->setHeader('Host', $request->getHeader('Host') . ":{$request->getPort()}");
}
if (!$request->getHeader('Origin')) {
$request->setHeader('Origin', str_replace('ws', 'http', $scheme) . '://' . $request->getHost());
}
// do protocol headers
if (count($subProtocols) > 0) {
$protocols = implode(',', $subProtocols);
if ($protocols != "") {
$request->setHeader('Sec-WebSocket-Protocol', $protocols);
}
}
return $request;
}
示例5: testOnRequestBeforeSendPOST
public function testOnRequestBeforeSendPOST()
{
$request = new Request('POST', 'www.url.com');
$event = new Event(array('request' => $request));
$this->plugin->onRequestBeforeSend($event);
$this->assertContains('key=' . $this->key, $request->getUrl());
}
示例6:
function it_set_up_request_custom_authentication_when_provided(Request $request, RequestBuilder $builder)
{
$this->beConstructedWith('digest');
$request->setAuth('username', 'password', 'digest')->shouldBeCalled(1);
$builder->getCredentials()->shouldBeCalled()->willReturn(['username' => 'username', 'password' => 'password']);
$this->secureRequest($request, $builder);
}
示例7: debug
public function debug()
{
$r = new Response();
var_dump($r->getReasonPhrase());
$req = new Request();
$req->getPath();
}
示例8: addAuthorizationHeader
/**
* @param \Guzzle\Http\Message\Request $request
* @param string $username
* @param string $password
*
* @return \BigOven\BigOvenAuthPlugin
*/
public function addAuthorizationHeader(Request $request, $username, $password)
{
$encodedString = base64_encode($username . ':' . $password);
$headerValue = 'Basic ' . $encodedString;
$request->addHeader('Authorization', $headerValue);
return $this;
}
示例9: secureRequest
public function secureRequest(Request $request, RequestBuilder $builder)
{
$credentials = $builder->getCredentials();
if (!isset($credentials['username']) || !isset($credentials['password'])) {
throw new \RuntimeException('You must specified a "username" and a "password" for the http basic authentication.');
}
$request->setAuth($credentials['username'], $credentials['password']);
}
示例10: testUrlEncodedSignature
/**
* Guzzle should take care of encoding signatures. This test is just a safety net to ensure that happens.
*/
public function testUrlEncodedSignature()
{
$expected = '1234 ] 5678';
$request = new Request('GET', "/fake?signature={$expected}");
$url = explode('signature=', $request->getUrl());
$signature = end($url);
$this->assertEquals(rawurlencode($expected), $signature, 'Request should be encoding the signature before sending (required by Ooyala).');
}
示例11: fireRequest
private function fireRequest(GuzzleRequest $request, $cookie)
{
try {
$response = $request->addCookie('authenticator', $cookie)->send();
return $response->json();
} catch (\Guzzle\Http\Exception\BadResponseException $client_error) {
return $this->app->abort($client_error->getResponse()->getStatusCode(), $client_error->getResponse()->getReasonPhrase());
}
}
示例12: testOnRequestBeforeSend
public function testOnRequestBeforeSend()
{
$request = new Request('GET', 'https://example.com');
$event = new Event(['request' => $request]);
$oauth = new OAuth('example');
$oauth->onRequestBeforeSend($event);
$this->assertTrue($request->getQuery()->hasKey('access_token'));
$this->assertEquals('example', $request->getQuery()->get('access_token'));
}
示例13: testCreatesPreSignedUrlWithXAmzHeaders
public function testCreatesPreSignedUrlWithXAmzHeaders()
{
$signature = new S3Signature();
$request = new Request('GET', 'https://s3.amazonaws.com', array('X-Amz-Acl' => 'public-read'));
$c = $this->getServiceBuilder()->get('s3');
$request->setClient($c);
$this->assertContains('x-amz-acl:public-read', $signature->createCanonicalizedString($request, time()));
$this->assertContains('&x-amz-acl=public-read', $signature->createPresignedUrl($request, $c->getCredentials(), time()));
}
示例14: request
public function request(Request $request)
{
try {
$response = $request->send();
} catch (\Exception $e) {
throw new ApiException($e->getMessage(), $e->getCode(), $e);
}
$apiResponse = new ApiResponse($response->getBody(), $response->getStatusCode(), $response->getContentType());
return $apiResponse;
}
示例15: testCreatesCanonicalizedQueryString
/**
* @covers Aws\Common\Signature\AbstractSignature::getCanonicalizedQueryString
* @dataProvider queryStringProvider
*/
public function testCreatesCanonicalizedQueryString($headers, $string)
{
// Make the method publicly callable
$method = new \ReflectionMethod('Aws\\Common\\Signature\\AbstractSignature', 'getCanonicalizedQueryString');
$method->setAccessible(true);
// Create a request and replace the headers with the test headers
$request = new Request('GET', 'http://www.example.com');
$request->getQuery()->replace($headers);
$this->assertEquals($string, $method->invoke($this->signature, $request));
}