Guzzle 异常和 "http_errors request option"

Guzzle Exceptions and "http_errors request option"

在 guzzle6 手册 (http://guzzle.readthedocs.org/en/latest/quickstart.html#exceptions) 中指出

A GuzzleHttp\Exception\ClientException is thrown for 400 level errors if the http_errors request option is set to true

这是什么"http_errors"设置,如何更改?

我试过:

$client = new \Guzzle\Http\Client();
$client->setDefaultOption('http_errors', false);

我不确定这是否有任何影响。除此之外,我在库源代码中的任何地方都找不到字符串 "http_errors",这让我怀疑我误解了文档。

那么如何更改此 "http_errors" setting/request 选项?

您需要使用 "exception" 选项。

这里有更多信息:http://guzzle.readthedocs.org/en/5.3/clients.html#exceptions

狂欢 6

 $client->get('/status/500', ['http_errors' => false]);

https://guzzle.readthedocs.io/en/latest/request-options.html#http-errors

此答案由@Alcalyn 在上面的评论中提供。