Guzzle Exceptions和“http_errors请求选项”

问题描述 投票:0回答:2

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

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

什么是“http_errors”设置,你如何改变它?

我试过了:

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

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

那么如何更改此“http_errors”设置/请求选项?

curl guzzle
2个回答
1
投票

对于Guzzle 6

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

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

这个答案是由@Alcalyn在上面的评论中提供的。


-1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.