本文整理汇总了PHP中Zend_Http_Response::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Response::factory方法的具体用法?PHP Zend_Http_Response::factory怎么用?PHP Zend_Http_Response::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Response
的用法示例。
在下文中一共展示了Zend_Http_Response::factory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLineBreaksCompatibility
public function testLineBreaksCompatibility()
{
$response_text_lf = file_get_contents(dirname(__FILE__) . '/_files/response_lfonly');
$res_lf = Zend_Http_Response::factory($response_text_lf);
$response_text_crlf = file_get_contents(dirname(__FILE__) . '/_files/response_crlf');
$res_crlf = Zend_Http_Response::factory($response_text_crlf);
$this->assertEquals($res_lf->getHeadersAsString(true), $res_crlf->getHeadersAsString(true), 'Responses headers do not match');
$this->assertEquals($res_lf->getBody(), $res_crlf->getBody(), 'Response bodies do not match');
}
示例2: request
/**
* Send the HTTP request and return a response
*
* @param string $method
* @return Zend_Http_Response
*/
public function request($method = null)
{
if (!$this->uri instanceof Zend_Uri_Http) {
throw new Zend_Http_Exception("No valid URI has been passed to the client");
}
if ($method) {
$this->setMethod($method);
}
// Prepare the request string
$body = $this->_prepare_body();
$headers = $this->_prepare_headers();
$request = $headers . "\r\n" . $body;
// Open the connection, send the request and read the response
$sock = $this->_connect();
$this->_write($sock, $request);
$response = $this->_read($sock);
$this->last_request = $request;
return Zend_Http_Response::factory($response);
}
示例3: request
/**
* Send the HTTP request and return an HTTP response object
*
* @param string $method
* @return Zend_Http_Response
*/
public function request($method = null)
{
if (!$this->uri instanceof Zend_Uri_Http) {
throw new Zend_Http_Client_Exception("No valid URI has been passed to the client");
}
if ($method) {
$this->setMethod($method);
}
$this->redirectCounter = 0;
$response = null;
// Send the first request. If redirected, continue.
do {
// Clone the URI and add the additional GET parameters to it
$uri = clone $this->uri;
$uri_params = array();
parse_str($uri->getQuery(), $uri_params);
$uri->setQuery(array_merge($uri_params, $this->paramsGet));
$body = $this->prepare_body();
$headers = $this->prepare_headers();
$request = implode("\r\n", $headers) . "\r\n" . $body;
$this->last_request = $request;
// Open the connection, send the request and read the response
$this->adapter->connect($uri->getHost(), $uri->getPort(), $uri->getScheme() == 'https' ? true : false);
$this->adapter->write($this->method, $uri, $this->config['httpversion'], $headers, $body);
$response = Zend_Http_Response::factory($this->adapter->read());
// Load cookies into cookie jar
if (isset($this->Cookiejar)) {
$this->Cookiejar->addCookiesFromResponse($response, $uri);
}
// If we got redirected, look for the Location header
if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
// Check whether we send the exact same request again, or drop the parameters
// and send a GET request
if ($response->getStatus() == 303 || !$this->config['strictredirects'] && ($response->getStatus() == 302 || $response->getStatus() == 301)) {
$this->resetParameters();
$this->setMethod(self::GET);
}
// If we got a well formed absolute URI
if (Zend_Uri_Http::check($location)) {
$this->setHeaders('host', null);
$this->setUri($location);
} else {
// Split into path and query and set the query
list($location, $query) = explode('?', $location, 2);
$this->uri->setQueryString($query);
// Else, if we got just an absolute path, set it
if (strpos($location, '/') === 0) {
$this->uri->setPath($location);
// Else, assume we have a relative path
} else {
// Get the current path directory, removing any trailing slashes
$path = rtrim(dirname($this->uri->getPath()), "/");
$this->uri->setPath($path . '/' . $location);
}
}
$this->redirectCounter++;
} else {
// If we didn't get any location, stop redirecting
break;
}
} while ($this->redirectCounter < $this->config['maxredirects']);
return $response;
}