本文整理汇总了PHP中Zend\Http\Response::isOk方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::isOk方法的具体用法?PHP Response::isOk怎么用?PHP Response::isOk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Response
的用法示例。
在下文中一共展示了Response::isOk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkStatusCode
/**
* Checks whether to handle this status code.
*
* @param HttpResponse $response
* @return boolean
*/
public function checkStatusCode(HttpResponse $response)
{
// Only 200 responses are cached by default
if (empty($this->config['http_codes_black_list'])) {
return $response->isOk();
}
$statusCode = $response->getStatusCode();
return !in_array($statusCode, (array) $this->config['http_codes_black_list']);
}
示例2: 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());
}