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


PHP HTTP_Request2::setCookieJar方法代码示例

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


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

示例1: testDefaultPrivacyEdit

 /**
  * Test that the default privacy setting is used when an existing
  * bookmark is updated with edit.php.
  */
 public function testDefaultPrivacyEdit()
 {
     $this->setUnittestConfig(array('defaults' => array('privacy' => 2)));
     list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
     $cookies = $req->getCookieJar();
     $req->setMethod(HTTP_Request2::METHOD_POST);
     $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit');
     $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
     $req->addPostParameter('status', '0');
     $res = $req->send();
     $this->assertEquals(200, $res->getStatus(), 'Adding bookmark failed: ' . $res->getBody());
     $bms = $this->bs->getBookmarks(0, null, $uId);
     $bm = reset($bms['bookmarks']);
     $bmId = $bm['bId'];
     $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
     $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
     $req2->setCookieJar($cookies);
     $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
     $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.');
     $req2->addPostParameter('submitted', '1');
     $res = $req2->send();
     $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed');
     $bm = $this->bs->getBookmark($bmId);
     $this->assertEquals('2', $bm['bStatus']);
 }
开发者ID:MarxGonzalez,项目名称:SemanticScuttle,代码行数:29,代码来源:editTest.php

示例2: testCookieJar

 public function testCookieJar()
 {
     $this->request->setUrl($this->baseUrl . 'setcookie.php?name=cookie_name&value=cookie_value');
     $req2 = clone $this->request;
     $this->request->setCookieJar()->send();
     $jar = $this->request->getCookieJar();
     $jar->store(array('name' => 'foo', 'value' => 'bar'), $this->request->getUrl());
     $response = $req2->setUrl($this->baseUrl . 'cookies.php')->setCookieJar($jar)->send();
     $this->assertEquals(serialize(array('cookie_name' => 'cookie_value', 'foo' => 'bar')), $response->getBody());
 }
开发者ID:SuhitNarayan,项目名称:SuhitNarayan-SEMANTICTECH,代码行数:10,代码来源:CommonNetworkTest.php

示例3: getLoggedInRequest

 /**
  * Creates a user and a HTTP_Request2 object, does a normal login
  * and prepares the cookies for the HTTP GET request object so that
  * the user is seen as logged in when requesting any HTML page.
  *
  * Useful for testing HTML pages or ajax URLs.
  *
  * @param string  $urlSuffix  Suffix for the URL
  * @param mixed   $auth       If user authentication is needed (true/false)
  *                            or array with username and password
  * @param boolean $privateKey True if to add user with private key
  *
  * @return array(HTTP_Request2, integer) HTTP request object and user id
  *
  * @uses getRequest()
  */
 protected function getLoggedInRequest($urlSuffix = null, $auth = true, $privateKey = null)
 {
     if (is_array($auth)) {
         list($username, $password) = $auth;
     } else {
         $username = 'testuser';
         $password = 'testpassword';
     }
     $uid = $this->addUser($username, $password, $privateKey);
     $req = new HTTP_Request2($GLOBALS['unittestUrl'] . '/login.php?unittestMode=1', HTTP_Request2::METHOD_POST);
     $cookies = $req->setCookieJar()->getCookieJar();
     $req->addPostParameter('username', $username);
     $req->addPostParameter('password', $password);
     $req->addPostParameter('submitted', 'Log In');
     $res = $req->send();
     //after login, we normally get redirected
     $this->assertEquals(302, $res->getStatus(), 'Login failure');
     $req = $this->getRequest($urlSuffix);
     $req->setCookieJar($cookies);
     return array($req, $uid);
 }
开发者ID:hrepp,项目名称:SemanticScuttle,代码行数:37,代码来源:TestBaseApi.php

示例4: testAddCookieToJar

 public function testAddCookieToJar()
 {
     $req = new HTTP_Request2();
     $req->setCookieJar();
     try {
         $req->addCookie('foo', 'bar');
         $this->fail('Expected HTTP_Request2_Exception was not thrown');
     } catch (HTTP_Request2_LogicException $e) {
     }
     $req->setUrl('http://example.com/path/file.php');
     $req->addCookie('foo', 'bar');
     $this->assertArrayNotHasKey('cookie', $req->getHeaders());
     $cookies = $req->getCookieJar()->getAll();
     $this->assertEquals(array('name' => 'foo', 'value' => 'bar', 'domain' => 'example.com', 'path' => '/path/', 'expires' => null, 'secure' => false), $cookies[0]);
 }
开发者ID:SuhitNarayan,项目名称:SuhitNarayan-SEMANTICTECH,代码行数:15,代码来源:Request2Test.php

示例5:

<?php

require 'HTTP/Request2.php';
$r = new HTTP_Request2();
$r->setCookieJar(true);
// log in
$r->setUrl('https://bank.example.com/login.php?user=donald&password=b1gmoney$');
$page = $r->send()->getBody();
// retrieve account balance
$r->setUrl('http://bank.example.com/balance.php?account=checking');
$page = $r->send()->getBody();
// make a deposit
$r->setUrl('http://bank.example.com/deposit.php');
$r->setMethod(HTTP_Request2::METHOD_POST)->addPostParameter('account', 'checking')->addPostParameter('amount', '122.44');
$page = $r->send()->getBody();
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:15,代码来源:cookies4.php


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