当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::addCookie方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Request::addCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::addCookie方法的具体用法?PHP Request::addCookie怎么用?PHP Request::addCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Request的用法示例。


在下文中一共展示了Request::addCookie方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testHoldsCookies

 /**
  * @covers Guzzle\Http\Message\Request
  */
 public function testHoldsCookies()
 {
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Multiple cookies by setting the Cookie header
     $this->request->setHeader('Cookie', '__utma=1.638370270.1344367610.1374365610.1944450276.2; __utmz=1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hl=de; PHPSESSID=ak93pqashi5uubuoq8fjv60897');
     $this->assertEquals('1.638370270.1344367610.1374365610.1944450276.2', $this->request->getCookie('__utma'));
     $this->assertEquals('1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', $this->request->getCookie('__utmz'));
     $this->assertEquals('de', $this->request->getCookie('hl'));
     $this->assertEquals('ak93pqashi5uubuoq8fjv60897', $this->request->getCookie('PHPSESSID'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     $this->request->removeHeader('Cookie');
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getHeader('Cookie'));
     // Remove a cookie value
     $this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
     $this->request->removeCookie('foo');
     $this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
     $this->request->addCookie('foo', 'bar');
     $this->assertEquals('baz=boo; foo=bar', (string) $this->request->getHeader('Cookie'));
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:35,代码来源:RequestTest.php

示例2: 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

示例3: setRequestCookies

 private function setRequestCookies(\Guzzle\Http\Message\Request $request)
 {
     if (!is_null($request->getCookies())) {
         foreach ($request->getCookies() as $name => $value) {
             $request->removeCookie($name);
         }
     }
     $cookieUrlMatcher = new \webignition\Cookie\UrlMatcher\UrlMatcher();
     foreach ($this->getConfiguration()->getCookies() as $cookie) {
         if ($cookieUrlMatcher->isMatch($cookie, $request->getUrl())) {
             $request->addCookie($cookie['name'], $cookie['value']);
         }
     }
 }
开发者ID:webignition,项目名称:url-resolver,代码行数:14,代码来源:Resolver.php

示例4: signRequest

 /**
  * @param \Guzzle\Http\Message\Request $request
  */
 public function signRequest(Request $request)
 {
     $url = $request->getPath();
     if ('POST' == $request->getMethod() && $request instanceof EntityEnclosingRequest) {
         $body = (string) $request->getBody();
         $hash = $this->signature->generate($body);
     } else {
         $url .= '?' . $request->getQuery();
         $hash = $this->signature->generate($url);
     }
     $request->addCookie('acquia_solr_time', $this->signature->getRequestTime());
     $request->addCookie('acquia_solr_nonce', $this->signature->getNonce());
     $request->addCookie('acquia_solr_hmac', $hash . ';');
     // The timestamp should be current for each request.
     $this->signature->unsetRequestTime();
 }
开发者ID:caxy,项目名称:acquia-sdk-php,代码行数:19,代码来源:AcquiaSearchAuthPlugin.php

示例5: testHoldsCookies

 /**
  * @covers Guzzle\Http\Message\Request
  */
 public function testHoldsCookies()
 {
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getHeader('Cookie'));
     // Remove a cookie value
     $this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
     $this->request->removeCookie('foo');
     $this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
 }
开发者ID:nickpeirson,项目名称:guzzle,代码行数:26,代码来源:RequestTest.php

示例6: testHoldsCookies

 /**
  * @covers Guzzle\Http\Message\Request
  */
 public function testHoldsCookies()
 {
     $cookie = $this->request->getCookie();
     $this->assertInstanceOf('Guzzle\\Http\\Cookie', $this->request->getCookie());
     // Ensure that the cookie will not affect the request
     $this->assertNull($this->request->getCookie('test'));
     $cookie->set('test', 'abc');
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getCookie());
     // Set the cookie using a cookie object
     $this->assertSame($this->request, $this->request->setCookie($cookie));
     $this->assertEquals($cookie->getAll(), $this->request->getCookie()->getAll());
     // Set the cookie using an array
     $this->assertSame($this->request, $this->request->setCookie(array('test' => 'def')));
     $this->assertEquals(array('test' => 'def'), $this->request->getCookie()->getAll());
     // Test using an invalid value
     try {
         $this->request->setCookie('a');
         $this->fail('Did not throw expected exception when passing invalid value');
     } catch (\InvalidArgumentException $e) {
     }
 }
开发者ID:norv,项目名称:guzzle,代码行数:39,代码来源:RequestTest.php

示例7: requestWithJsonResponse

 public static function requestWithJsonResponse(GuzzleRequest $request, Application $app, $cookie)
 {
     try {
         $response = $request->addCookie("authenticator", $cookie)->send();
         $headers = $response->getHeaders()->toArray();
         return $app->json(json_decode($response->getBody()), 200, $headers);
     } catch (\Guzzle\Http\Exception\BadResponseException $client_error) {
         return $app->abort($client_error->getResponse()->getStatusCode(), $client_error->getResponse()->getReasonPhrase());
     }
 }
开发者ID:faouzic,项目名称:composer-conversation-proxy-provider,代码行数:10,代码来源:DumbMethodsProxy.php


注:本文中的Guzzle\Http\Message\Request::addCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。