本文整理汇总了PHP中Zend\Http\Response::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getBody方法的具体用法?PHP Response::getBody怎么用?PHP Response::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Response
的用法示例。
在下文中一共展示了Response::getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: theStatusCodeShouldBe
/**
* @Then the status code should be :code
*/
public function theStatusCodeShouldBe($code)
{
if ($this->response->getStatusCode() != $code) {
echo $this->response->getBody();
}
\PHPUnit_Framework_Assert::assertEquals($code, $this->response->getStatusCode());
}
示例2: plugin_preview_action
function plugin_preview_action()
{
global $vars;
$page = isset($vars['page']) ? $vars['page'] : '';
$modified = 0;
$response = new Response();
if (!empty($page)) {
$wiki = Factory::Wiki($page);
if ($wiki->isReadable()) {
$source = $wiki->get();
array_splice($source, 10);
$response->setStatusCode(Response::STATUS_CODE_200);
$response->setContent('<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n" . RendererFactory::factory($source));
$headers = Header::getHeaders('text/xml', $wiki->time());
} else {
$response->setStatusCode(Response::STATUS_CODE_404);
$headers = Header::getHeaders('text/xml');
}
} else {
$response->setStatusCode(Response::STATUS_CODE_404);
$headers = Header::getHeaders('text/xml');
}
$response->getHeaders()->addHeaders($headers);
header($response->renderStatusLine());
foreach ($response->getHeaders() as $_header) {
header($_header->toString());
}
echo $response->getBody();
exit;
}
示例3: _parseParameters
protected function _parseParameters(HTTPResponse $response)
{
$params = array();
$body = $response->getBody();
if (empty($body)) {
return;
}
$tokenFormat = $this->getTokenFormat();
switch ($tokenFormat) {
case 'json':
$params = \Zend\Json\Json::decode($body);
break;
case 'jsonp':
break;
case 'pair':
$parts = explode('&', $body);
foreach ($parts as $kvpair) {
$pair = explode('=', $kvpair);
$params[rawurldecode($pair[0])] = rawurldecode($pair[1]);
}
break;
default:
throw new Exception\InvalidArgumentException(sprintf('Unable to handle access token response by undefined format %', $tokenFormat));
}
return (array) $params;
}
示例4: handleResponse
/**
* {@inheritdoc}
* @see \InoOicClient\Oic\AbstractResponseHandler::handleResponse()
*/
public function handleResponse(\Zend\Http\Response $httpResponse)
{
$responseData = null;
$decodeException = null;
try {
$responseData = $this->getJsonCoder()->decode($httpResponse->getBody());
} catch (\Exception $e) {
$decodeException = $e;
}
if (!$httpResponse->isSuccess()) {
if (isset($responseData[Param::ERROR])) {
$error = $this->getErrorFactory()->createErrorFromArray($responseData);
$this->setError($error);
return;
} else {
throw new HttpErrorStatusException(sprintf("Error code '%d' from server", $httpResponse->getStatusCode()));
}
}
if (null !== $decodeException) {
throw new InvalidResponseFormatException('The HTTP response does not contain valid JSON', null, $decodeException);
}
try {
$this->response = $this->getResponseFactory()->createResponse($responseData);
} catch (\Exception $e) {
throw new Exception\InvalidResponseException(sprintf("Invalid response: [%s] %s", get_class($e), $e->getMessage()), null, $e);
}
}
示例5: _call
/**
*
* @param string $method
* @param array $options
* @return array|boolean
*/
protected function _call($method, $options = null)
{
if (!empty($options) && !is_array($options)) {
throw new Exception\InvalidArgumentException("The options must be an array");
}
$client = $this->getHttpClient();
$paramGet = array('format' => self::FORMAT_API, 'api_key' => $this->apiKey, 'sig' => $this->_computeSignature(), 'v' => $this->apiVersion);
if (!empty($options)) {
$get = '';
foreach ($options as $key => $value) {
if (is_array($value)) {
foreach ($value as $val) {
$get .= $key . '=' . urlencode($val) . '&';
}
} else {
$paramGet[$key] = $value;
}
}
}
$client->setParameterGet($paramGet);
if (!empty($get)) {
$client->setUri(self::URL_API . $method . '?' . $get);
} else {
$client->setUri(self::URL_API . $method);
}
$this->lastResponse = $client->send();
return json_decode($this->lastResponse->getBody(), true);
}
示例6: dispatchRequestAndDecodeResponse
protected function dispatchRequestAndDecodeResponse($url, $method, $data = null)
{
$request = new Request();
$this->lastResponse = null;
$request->getHeaders()->addHeaders(array('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 'Accept' => 'application/json', 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0'));
if (!empty($this->host)) {
$request->getHeaders()->addHeaders(array('Host' => $this->host));
}
if (!empty($this->key)) {
$request->getHeaders()->addHeaders(array('Authorization' => 'Bearer ' . $this->key));
}
$request->setUri($url);
$request->setMethod($method);
if (is_null($data)) {
$data = array();
}
if (isset($this->key)) {
$data["auth"] = $this->key;
}
if ($method == "POST" || $method == "PUT") {
$request->setPost(new Parameters($data));
if (isset($this->key)) {
$request->setQuery(new Parameters(array('auth' => $this->key)));
}
} else {
$request->setQuery(new Parameters($data));
}
$this->lastResponse = $this->httpClient->send($request);
if ($this->lastResponse->isSuccess()) {
return json_decode($this->lastResponse->getBody(), true);
} else {
return array('error' => true, 'headers' => array("code" => $this->lastResponse->getStatusCode(), "reasons" => $this->lastResponse->getReasonPhrase()), 'body' => json_decode($this->lastResponse->getBody(), true));
}
}
示例7: _parseResponse
protected function _parseResponse(\Zend\Http\Response $response)
{
$body = \Zend\Json\Decoder::decode($response->getBody());
if (array_key_exists(self::PARSE_ERROR, $body)) {
throw new \Exception($body[self::PARSE_REASON]);
}
return $body;
}
示例8: getCrawler
/**
* Create the crawler from body given by response.
*
* @param Response $response
*
* @return Crawler
*/
protected function getCrawler(Response $response)
{
if (null === $this->crawler) {
$this->crawler = new Crawler();
$this->crawler->addContent($response->getBody());
$this->crawler = $this->crawler->filter('#wbCalendar .date');
}
return $this->crawler;
}
示例9: createResponseFromHttpResponse
/**
* Creates a Perun response from the HTTP response.
*
* @param Http\Response $httpResponse
* @param Request $request
* @throws GeneralException\MissingDependencyException
* @return Response
*/
public function createResponseFromHttpResponse(Http\Response $httpResponse, Request $request)
{
$serializer = $this->getSerializer();
if (!$serializer) {
throw new GeneralException\MissingDependencyException('serializer', $this);
}
$payload = $this->getPayloadFactory()->createPayload();
$payload = $serializer->unserialize($httpResponse->getBody(), $payload);
return $this->createResponseFromPayload($payload, $request);
}
示例10: __construct
/**
* Constructor
*
* Assigns the HttpResponse to a property, as well as the body
* representation. It then attempts to decode the body as JSON.
*
* @param HttpResponse $httpResponse
* @throws Exception\DomainException if unable to decode JSON response
*/
public function __construct(HttpResponse $httpResponse)
{
$this->httpResponse = $httpResponse;
$this->rawBody = $httpResponse->getBody();
try {
$jsonBody = Json::decode($this->rawBody, Json::TYPE_OBJECT);
$this->jsonBody = $jsonBody;
} catch (JsonException $e) {
throw new Exception\DomainException(sprintf('Unable to decode response from twitter: %s', $e->getMessage()), 0, $e);
}
}
示例11: setFromResponseObj
/**
* @param HttpResponse $response
*
* @return $this
*/
public function setFromResponseObj(HttpResponse $response)
{
$content = json_decode($response->getBody(), true);
if (array_key_exists('success', $content)) {
$this->setStatus($content['success']);
}
if (array_key_exists('error', $content)) {
$this->setError($content['error']);
}
return $this;
}
示例12: getMetaData
/**
* List of links given by response http body.
* Content type is application/link-format.
*
* @param Response $response
*
* @return Snapshot[]
*/
protected function getMetaData(Response $response)
{
$links = array();
foreach (explode("\n", $response->getBody()) as $link) {
$elements = $this->decodeLink($link);
if (!isset($elements['rel'], $elements['datetime'])) {
continue;
}
$links[] = new Snapshot(\DateTime::createFromFormat('D, d M Y H:i:s \\G\\M\\T', $elements['datetime']), substr($elements['link'], 1, -1));
}
return $links;
}
示例13: getDocument
/**
* Gets the document object for this response
*
* @return DOMDocument the DOM Document for this response.
*/
public function getDocument()
{
try {
$body = $this->_httpResponse->getBody();
} catch (\Zend\Http\Exception\ExceptionInterface $e) {
$body = false;
}
if ($this->_document === null) {
if ($body !== false) {
// turn off libxml error handling
$errors = libxml_use_internal_errors();
$this->_document = new DOMDocument();
if (!$this->_document->loadXML($body)) {
$this->_document = false;
}
// reset libxml error handling
libxml_clear_errors();
libxml_use_internal_errors($errors);
} else {
$this->_document = false;
}
}
return $this->_document;
}
示例14: mapResult
/**
* Transform the raw http response into a Generic Result object
*
* @param Response $response
* @param ClassMetadata $metadata
* @return Result
*/
public function mapResult(Response $response, ClassMetadata $metadata)
{
$className = $metadata->getClassName();
$result = new Result();
$foreign = json_decode($response->getBody());
$result->setTotal($foreign->hits->total);
foreach ($foreign->hits->hits as $foreignHit) {
$hit = new Hit();
$hit->setScore($foreignHit->_score);
$hit->setDocument($foreignHit->_source);
$result->getHits()->add($hit);
}
return $result;
}
示例15: send
/**
* Send Http request to retrieve datas
* @access protected
* @param string $service Service to call
* @param string $type Resource type to retrieve (for search service)
* @param array $parameters Parameters used for request
* @throws \Zend\Http\Exception\RuntimeException
* @return \stdClass
*/
protected function send($service, $type, $parameters)
{
// reset old parameters
$this->getHttpClient()->resetParameters();
// setup Http headers
$headers = array(ContentTypeHeader::fromString('Content-Type: ' . HttpClient::ENC_URLENCODED));
// setup HttpClient
$this->getHttpClient()->setMethod(HttpRequest::METHOD_GET);
$this->getHttpClient()->setParameterGet($parameters);
$this->getHttpClient()->setHeaders($headers);
// generate URI and set to HttpClient
$this->getHttpClient()->setUri($this->generateURI($service, $type));
// get HttpResponse
$this->response = $this->getHttpClient()->send();
// is HttpRequest ok ?
if (!$this->response->isOk()) {
// throw RuntimeException
throw new ZendRuntimeException(sprintf('Invalid status code: %d', $this->response->getStatusCode()));
}
// return decode object
return \Zend\Json\Decoder::decode($this->response->getBody());
}