本文整理汇总了PHP中GuzzleHttp\Message\Response::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getStatusCode方法的具体用法?PHP Response::getStatusCode怎么用?PHP Response::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\Response
的用法示例。
在下文中一共展示了Response::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deduce
/**
* @return ErrorResponse|SuccessResponse
*/
public function deduce()
{
/* @var array $response */
$response = (array) $this->response->json();
if (array_key_exists('type', $response) && $response['type'] === 'error') {
return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
示例2: __construct
public function __construct(Response $response)
{
try {
$this->details = $response->json();
$message = $this->details['error']['message'];
} catch (ParseException $e) {
$message = $response->getReasonPhrase();
}
parent::__construct(sprintf('The request failed and returned an invalid status code ("%d") : %s', $response->getStatusCode(), $message), $response->getStatusCode());
}
示例3: createMessage
/**
* @param Response $response
*
* @return string
*/
protected static function createMessage(Response $response)
{
if ($response->getStatusCode() != 400) {
return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true);
}
$message = 'Some errors occurred:';
foreach ($response->xml()->error as $error) {
$message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message;
}
return $message;
}
示例4: checkResponse
/**
* Check the return of a request response
*
* @param Response $response
* @return false if error, decoded response if valid status
* @author Niko
*/
private function checkResponse(Response $response)
{
if ($response->getStatusCode() != 200) {
$res = $response->json();
var_dump($response->getStatusCode());
if (isset($res['Error'])) {
$this->log($response->getStatusCode(), $res['Error']);
}
return false;
}
return $response->json();
}
示例5: handleResponse
protected function handleResponse(Response $response)
{
$code = $response->getStatusCode();
if ($code == 200) {
return json_decode($response->getBody()->getContents(), true);
}
if ($code == 401 && $this->requiresToken) {
// Unauthorized, invalidate token
$this->tokenStore->storeToken(null);
}
throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
}
示例6: handleResponse
/**
* @param \GuzzleHttp\Message\Response $response
* @return Error
*/
protected function handleResponse($response)
{
$contentType = $response->getHeader('content-type');
if (stripos($contentType, 'application/json') === false) {
return $response;
}
$json = $response->json();
if ($response->getStatusCode() >= 400) {
// oops an error with the response
return new Error($response->getStatusCode(), $json['code'], $json['message']);
}
return $json;
}
示例7: handleResponse
/**
* @param Response $response
* @return array|mixed
* @throws JsonApiResponseException
*/
public function handleResponse($response)
{
$contentType = $response->getHeader('content-type');
// if its not json, then just return the response and handle it in your own object.
if (stripos($contentType, 'application/json') === false) {
return $response;
}
$json = $response->json();
// adobe says hey this didn't work!
if ($response->getStatusCode() >= 400) {
// oops an error with the response, from Adobe complaining about something in your code.
throw new JsonApiResponseException($response->getStatusCode(), $json['message'], $json['code']);
}
return $json;
}
示例8: formatProvider
public function formatProvider()
{
$request = new Request('PUT', '/', ['x-test' => 'abc'], Stream::factory('foo'));
$response = new Response(200, ['X-Baz' => 'Bar'], Stream::factory('baz'));
$err = new RequestException('Test', $request, $response);
return [['{request}', [$request], (string) $request], ['{response}', [$request, $response], (string) $response], ['{request} {response}', [$request, $response], $request . ' ' . $response], ['{request} {response}', [$request], $request . ' '], ['{req_headers}', [$request], "PUT / HTTP/1.1\r\nx-test: abc"], ['{res_headers}', [$request, $response], "HTTP/1.1 200 OK\r\nX-Baz: Bar"], ['{res_headers}', [$request], 'NULL'], ['{req_body}', [$request], 'foo'], ['{res_body}', [$request, $response], 'baz'], ['{res_body}', [$request], 'NULL'], ['{method}', [$request], $request->getMethod()], ['{url}', [$request], $request->getUrl()], ['{resource}', [$request], $request->getResource()], ['{req_version}', [$request], $request->getProtocolVersion()], ['{res_version}', [$request, $response], $response->getProtocolVersion()], ['{res_version}', [$request], 'NULL'], ['{host}', [$request], $request->getHost()], ['{hostname}', [$request, $response], gethostname()], ['{hostname}{hostname}', [$request, $response], gethostname() . gethostname()], ['{code}', [$request, $response], $response->getStatusCode()], ['{code}', [$request], 'NULL'], ['{phrase}', [$request, $response], $response->getReasonPhrase()], ['{phrase}', [$request], 'NULL'], ['{error}', [$request, $response, $err], 'Test'], ['{error}', [$request], 'NULL'], ['{req_header_x-test}', [$request], 'abc'], ['{req_header_x-not}', [$request], ''], ['{res_header_X-Baz}', [$request, $response], 'Bar'], ['{res_header_x-not}', [$request, $response], ''], ['{res_header_X-Baz}', [$request], 'NULL']];
}
示例9: handleResponse
protected function handleResponse(Response $response)
{
if ($response->getStatusCode() == 200) {
return $response->getBody()->getContents();
}
throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
}
示例10: status
/**
* {@inheritdoc}
*/
public function status()
{
if ($this->response) {
return $this->response->getStatusCode();
}
return false;
}
示例11: createResponse
/**
* Taken from Mink\BrowserKitDriver
*
* @param Response $response
*
* @return \Symfony\Component\BrowserKit\Response
*/
protected function createResponse(Response $response)
{
$contentType = $response->getHeader('Content-Type');
$matches = null;
if (!$contentType or strpos($contentType, 'charset=') === false) {
$body = $response->getBody(true);
if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
$response->setHeader('Content-Type', $contentType);
}
$headers = $response->getHeaders();
$status = $response->getStatusCode();
$matchesMeta = null;
$matchesHeader = null;
$isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
$isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
$matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
$uri = $this->getAbsoluteUri($matches[2]);
$partsUri = parse_url($uri);
$partsCur = parse_url($this->getHistory()->current()->getUri());
foreach ($partsCur as $key => $part) {
if ($key === 'fragment') {
continue;
}
if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
$status = 302;
$headers['Location'] = $uri;
break;
}
}
}
return new BrowserKitResponse($response->getBody(), $status, $headers);
}
示例12: debug
function debug(\GuzzleHttp\Message\Response $response)
{
$this->dump_respuesta = 'status: ' . $response->getStatusCode() . "<br/>body: <br/>" . $response->getBody();
//un string encodeado utf-8
$this->dump_url = $response->getEffectiveUrl();
//un string encodeado utf-8
}
示例13: Payment
function it_maps_declined_response_402_to_payment_result_object(ClientException $exception, Response $response, ResultObjectMapperInterface $resultMapper, MethodInterface $method)
{
$result = ['error' => 'Error string'];
$resultObject = new Payment();
$response->getStatusCode()->willReturn(402);
$response->json()->willReturn($result);
$method->createResultObject()->willReturn($resultObject);
$exception->getResponse()->willReturn($response);
$resultMapper->map($result, $resultObject)->shouldBeCalled()->willReturn($resultObject);
$this->get($exception, $method)->getResult()->shouldReturn($resultObject);
}
示例14: validateStatusCode
private function validateStatusCode(\GuzzleHttp\Message\Response $response, Spec\Response $responseSpec, UseCaseValidationReport $report)
{
if ($responseSpec->getStatusCode()) {
$expectedCode = $responseSpec->getStatusCode();
$actualCode = $response->getStatusCode();
if ($expectedCode !== $actualCode) {
$message = sprintf("\t\t<error>Response code should be %s actual value is %s</error>", $expectedCode, $actualCode);
$this->addViolation($message);
$report->setStatusCodeViolation($message);
}
}
}
示例15: handleResponse
/**
* @param Response $response
* @return \GuzzleHttp\Stream\StreamInterface|mixed|null|string
* @throws ApiException
*/
protected function handleResponse(Response $response)
{
if ($response->getStatusCode() == 200) {
$stream = $response->getBody();
if ($this->returnStream == true) {
return $stream;
} else {
return parent::handleResponse($response);
}
}
throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
}