本文整理汇总了PHP中HTTP_Request2::getCookieJar方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2::getCookieJar方法的具体用法?PHP HTTP_Request2::getCookieJar怎么用?PHP HTTP_Request2::getCookieJar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request2
的用法示例。
在下文中一共展示了HTTP_Request2::getCookieJar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: sendRequest
/**
* Sends request to the remote server and returns its response
*
* @param HTTP_Request2
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
public function sendRequest(HTTP_Request2 $request)
{
$this->request = $request;
// Use global request timeout if given, see feature requests #5735, #8964
if ($timeout = $request->getConfig('timeout')) {
$this->deadline = time() + $timeout;
} else {
$this->deadline = null;
}
try {
$keepAlive = $this->connect();
$headers = $this->prepareHeaders();
if (false === @fwrite($this->socket, $headers, strlen($headers))) {
throw new HTTP_Request2_MessageException('Error writing request');
}
// provide request headers to the observer, see request #7633
$this->request->setLastEvent('sentHeaders', $headers);
$this->writeBody();
if ($this->deadline && time() > $this->deadline) {
throw new HTTP_Request2_MessageException('Request timed out after ' . $request->getConfig('timeout') . ' second(s)', HTTP_Request2_Exception::TIMEOUT);
}
$response = $this->readResponse();
if ($jar = $request->getCookieJar()) {
$jar->addCookiesFromResponse($response, $request->getUrl());
}
if (!$this->canKeepAlive($keepAlive, $response)) {
$this->disconnect();
}
if ($this->shouldUseProxyDigestAuth($response)) {
return $this->sendRequest($request);
}
if ($this->shouldUseServerDigestAuth($response)) {
return $this->sendRequest($request);
}
if ($authInfo = $response->getHeader('authentication-info')) {
$this->updateChallenge($this->serverChallenge, $authInfo);
}
if ($proxyInfo = $response->getHeader('proxy-authentication-info')) {
$this->updateChallenge($this->proxyChallenge, $proxyInfo);
}
} catch (Exception $e) {
$this->disconnect();
}
unset($this->request, $this->requestBody);
if (!empty($e)) {
$this->redirectCountdown = null;
throw $e;
}
if (!$request->getConfig('follow_redirects') || !$response->isRedirect()) {
$this->redirectCountdown = null;
return $response;
} else {
return $this->handleRedirect($request, $response);
}
}
示例3: sendRequest
/**
* Sends request to the remote server and returns its response
*
* @param HTTP_Request2
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
public function sendRequest(HTTP_Request2 $request)
{
if (!extension_loaded('curl')) {
throw new HTTP_Request2_LogicException('cURL extension not available', HTTP_Request2_Exception::MISCONFIGURATION);
}
$this->request = $request;
$this->response = null;
$this->position = 0;
$this->eventSentHeaders = false;
$this->eventReceivedHeaders = false;
try {
if (false === curl_exec($ch = $this->createCurlHandle())) {
$e = self::wrapCurlError($ch);
}
} catch (Exception $e) {
}
if (isset($ch)) {
$this->lastInfo = curl_getinfo($ch);
curl_close($ch);
}
$response = $this->response;
unset($this->request, $this->requestBody, $this->response);
if (!empty($e)) {
throw $e;
}
if ($jar = $request->getCookieJar()) {
$jar->addCookiesFromResponse($response, $request->getUrl());
}
if (0 < $this->lastInfo['size_download']) {
$request->setLastEvent('receivedBody', $response);
}
return $response;
}
示例4: sendRequest
/**
* Sends request to the remote server and returns its response
*
* @param HTTP_Request2 $request HTTP request message
*
* @return HTTP_Request2_Response
* @throws HTTP_Request2_Exception
*/
public function sendRequest(HTTP_Request2 $request)
{
$this->request = $request;
try {
$keepAlive = $this->connect();
$headers = $this->prepareHeaders();
$this->socket->write($headers);
// provide request headers to the observer, see request #7633
$this->request->setLastEvent('sentHeaders', $headers);
$this->writeBody();
$response = $this->readResponse();
if ($jar = $request->getCookieJar()) {
$jar->addCookiesFromResponse($response, $request->getUrl());
}
if (!$this->canKeepAlive($keepAlive, $response)) {
$this->disconnect();
}
if ($this->shouldUseProxyDigestAuth($response)) {
return $this->sendRequest($request);
}
if ($this->shouldUseServerDigestAuth($response)) {
return $this->sendRequest($request);
}
if ($authInfo = $response->getHeader('authentication-info')) {
$this->updateChallenge($this->serverChallenge, $authInfo);
}
if ($proxyInfo = $response->getHeader('proxy-authentication-info')) {
$this->updateChallenge($this->proxyChallenge, $proxyInfo);
}
} catch (Exception $e) {
$this->disconnect();
}
unset($this->request, $this->requestBody);
if (!empty($e)) {
$this->redirectCountdown = null;
throw $e;
}
if (!$request->getConfig('follow_redirects') || !$response->isRedirect()) {
$this->redirectCountdown = null;
return $response;
} else {
return $this->handleRedirect($request, $response);
}
}
示例5: 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]);
}