這三種Guzzle( guzzlehttp/guzzle)方法有什么區別:
use Illuminate\Support\Facades\Http;
$response = Http::get('http://example.com');
- $response-> ok() : bool;
- $回應->成功():布爾;
- $response-> failed() : bool;
什么時候優先使用其中一種方法比另一種更有意義?
提前致謝!
uj5u.com熱心網友回復:
這些方法來自 Laravel
public function success() { return $this->status() >= 200 && $this->status() < 300; }
公共函式 ok() { 回傳 $this->status() === 200; }
public function failed() { return $this->serverError() || $this->clientError(); }
肉眼可以看出差異
success() - 當狀態為 200 、 300 時回傳真
ok() - 僅當 status = 200 時回傳 true
failed() - 如果有任何錯誤,則回傳 bool
什么時候優先使用其中一種方法比另一種更有意義?
這取決于代碼和需要
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/381829.html
上一篇:Laravel聯系表無法正常作業
