【问题标题】:Guzzle Exceptions and "http_errors request option"Guzzle 异常和“http_errors 请求选项”
【发布时间】:2018-09-09 22:38:26
【问题描述】:

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

如果 http_errors 请求选项设置为 true,则会针对 400 级错误抛出 GuzzleHttp\Exception\ClientException

这个“http_errors”设置是什么,如何更改?

我试过了:

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

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

那么我该如何更改这个“http_errors”设置/请求选项?

【问题讨论】:

标签: curl guzzle


【解决方案1】:

对于 Guzzle 6

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

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

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

【讨论】:

    【解决方案2】:

    您需要使用“例外”选项。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-19
      • 2016-10-06
      • 2022-11-28
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      相关资源
      最近更新 更多