本文整理匯總了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());
}