Laravels guzzlehttp/guzzle中ok()、successful()和failed()有什么区别?
What are the differences between ok(), successful() and failed() in Laravels guzzlehttp/guzzle?
这三种 Guzzle (guzzlehttp/guzzle
) 方法有什么区别:
use Illuminate\Support\Facades\Http;
$response = Http::get('http://example.com');
- $response->ok() : bool;
- $response->成功() : bool;
- $response->failed() : bool;
什么时候优先使用其中一种方法比另一种更有意义?
提前致谢!
这些方法来自Laravel
public function successful() { return $this->status() >= 200 &&
$this->status() < 300; }
public function ok() { return $this->status() === 200; }
public function failed() { return $this->serverError() ||
$this->clientError(); }
而且肉眼也能看出区别
successful() -return 当状态介于 200 和 300 之间时为真
ok() - return 仅当 status = 200
时为真
failed() - return bool 如果有任何错误
And when does it make sense to use one of these methods in preference
to the other?
It depends on the code and the need
这三种 Guzzle (guzzlehttp/guzzle
) 方法有什么区别:
use Illuminate\Support\Facades\Http;
$response = Http::get('http://example.com');
- $response->ok() : bool;
- $response->成功() : bool;
- $response->failed() : bool;
什么时候优先使用其中一种方法比另一种更有意义?
提前致谢!
这些方法来自Laravel
public function successful() { return $this->status() >= 200 && $this->status() < 300; }
public function ok() { return $this->status() === 200; }
public function failed() { return $this->serverError() || $this->clientError(); }
而且肉眼也能看出区别
successful() -return 当状态介于 200 和 300 之间时为真
ok() - return 仅当 status = 200
时为真failed() - return bool 如果有任何错误
And when does it make sense to use one of these methods in preference to the other?
It depends on the code and the need