當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。