本文整理汇总了PHP中Guzzle\Http\Message\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'));
}
}
开发者ID:KANU82,项目名称:guzzle,代码行数:25,代码来源:DefaultRevalidationTest.php
示例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);
}
开发者ID:cosmorogers,项目名称:http-mock,代码行数:7,代码来源:RequestCollectionFacadeTest.php
示例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;
}
开发者ID:yuri-sagalovich,项目名称:nextcaller-php-api,代码行数:37,代码来源:NextCallerBaseClient.php
示例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;
}
开发者ID:brainverb,项目名称:Pawl,代码行数:27,代码来源:Factory.php
示例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());
}
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:7,代码来源:KeyAuthPluginTest.php
示例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);
}
开发者ID:puterakahfi,项目名称:FriendlyContexts,代码行数:7,代码来源:HttpExtensionSpec.php
示例7: debug
public function debug()
{
$r = new Response();
var_dump($r->getReasonPhrase());
$req = new Request();
$req->getPath();
}
开发者ID:arthurwayne,项目名称:ovh-sdk-php,代码行数:7,代码来源:VoiceConsumptionException.php
示例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;
}
开发者ID:cpliakas,项目名称:bigoven-php,代码行数:14,代码来源:BigOvenAuthPlugin.php
示例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']);
}
开发者ID:puterakahfi,项目名称:FriendlyContexts,代码行数:8,代码来源:HttpBasicExtension.php
示例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).');
}
开发者ID:sheknows,项目名称:ooyala-api-client,代码行数:11,代码来源:SignatureTest.php
示例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());
}
}
开发者ID:faouzic,项目名称:composer-conversation-proxy-provider,代码行数:9,代码来源:ConversationManager.php
示例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'));
}
开发者ID:mpscholten,项目名称:github-api,代码行数:9,代码来源:OAuthTest.php
示例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()));
}
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:9,代码来源:S3SignatureTest.php
示例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;
}
开发者ID:spiasecki,项目名称:ubirimi,代码行数:10,代码来源:GuzzleClientAdapter.php
示例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));
}
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:14,代码来源:AbstractSignatureTest.php
示例16: testAssertEmptyParametersAreStrippedWhenSignRequest
/**
* @covers PusherSignature::signRequest
*/
public function testAssertEmptyParametersAreStrippedWhenSignRequest()
{
$request = new HttpRequest('POST', '/apps/3/events');
// We set variables in query to have always the same result
$request->getQuery()->replace(array('key-with-value' => 'value', 'key-without-value' => ''));
$this->pusherSignature->signRequest($request, $this->credentials);
$queryParameters = $request->getQuery()->toArray();
$this->assertArrayHasKey('key-with-value', $queryParameters);
$this->assertArrayNotHasKey('key-without-value', $queryParameters);
}
开发者ID:GedConk,项目名称:zfr-pusher,代码行数:13,代码来源:PusherSignatureTest.php
示例17: setRequestAuthentication
public function setRequestAuthentication(\Guzzle\Http\Message\Request $request)
{
$oauthAccessToken = $this->configuration->get('oauthAccessToken');
// Do we have an oAuth2 access token?
if (!empty($oauthAccessToken)) {
$request->setHeader('Authorization', 'Bearer ' . $oauthAccessToken);
} else {
// Otherwise, use basic authentication
$request->setAuth($this->configuration->get('apiToken'), $this->configuration->get('apiSecret'));
}
return $request;
}
开发者ID:TheJaniceTong,项目名称:PhpSdk,代码行数:12,代码来源:Request.php
示例18: testFiltersCacheKey
public function testFiltersCacheKey()
{
$request = new Request('GET', 'http://foo.com?a=b&c=d', array('Abc' => '123', 'Def' => '456'));
$request->getParams()->set(DefaultCacheKeyProvider::CACHE_KEY_FILTER, 'header=Def; query=c');
$provider = new DefaultCacheKeyProvider();
$provider->getCacheKey($request);
$this->assertNotEmpty($request->getParams()->get(DefaultCacheKeyProvider::CACHE_KEY));
$cloned = clone $request;
$cloned->getQuery()->remove('c');
$cloned->removeHeader('Def');
$this->assertEquals((string) $cloned, $request->getParams()->get(DefaultCacheKeyProvider::CACHE_KEY_RAW));
}
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:12,代码来源:DefaultCacheKeyProviderTest.php
示例19: testListenerShouldAppendToRemoteHeadersAddTokenHeader
public function testListenerShouldAppendToRemoteHeadersAddTokenHeader()
{
$token = 'foo';
$requestStack = new RequestStack();
$plugin = new RequestTokenPlugin($token, $requestStack);
$httpRequest = new \Symfony\Component\HttpFoundation\Request();
$httpRequest->headers->set('x-remote-request-token', 'bar');
$requestStack->push($httpRequest);
$guzzleRequest = new Request('GET', 'http://example.com');
$event = new Event(array('request' => $guzzleRequest));
$plugin->onBeforeRequestSend($event);
$this->assertEquals('bar foo', $guzzleRequest->getHeaders()->get('x-remote-request-token'));
}
开发者ID:aptoma,项目名称:silex-extras,代码行数:13,代码来源:RequestTokenPluginTest.php
示例20: testSignsRequestsProperly
/**
* @covers Aws\Common\Signature\SignatureListener
*/
public function testSignsRequestsProperly()
{
$request = new Request('GET', 'http://www.example.com');
$request->getEventDispatcher();
$credentials = new Credentials('a', 'b');
$signature = $this->getMock('Aws\\Common\\Signature\\SignatureV4');
// Ensure that signing the request occurred once with the correct args
$signature->expects($this->once())->method('signRequest')->with($this->equalTo($request), $this->equalTo($credentials));
$listener = new SignatureListener($credentials, $signature);
// Create a mock event
$event = new Event(array('request' => $request));
$listener->onRequestBeforeSend($event);
}
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:16,代码来源:SignatureListenerTest.php
注:本文中的Guzzle\Http\Message\Request类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论