guzzlehttp resulted in a `409 Conflict` response 访问网址 laravel thinkphp

这篇博客主要讨论了在使用 Guzzle HTTP 客户端时遇到409 Conflict响应的问题。作者指出,常规配置如设置'verify'为false并未解决问题,但通过将'http_errors'设置为false可以避免返回错误。文中还引用了源码片段来解释这一行为。文章适合对 PHP 和 Guzzle 有经验的开发者,特别是那些在API调用中遇到冲突错误的读者。
摘要由CSDN通过智能技术生成
[409] ClientException in RequestException.php line 113
Client error: `GET http://b.k2.fwycg.com:8170/wgs/v1/openapi/products?productName=&upcBarcode=&barcoder=&fnsku=&businessCode=&warehouseCode=US-HSAJ` resulted in a `409 Conflict` response

搜索了很多资料,

new Client([
    'header' => [
        'Accept' => 'application/json',
        'Content-Type' => 'application/x-www-form-urlencoded'
    ],
    'verify' => false
]);

    默认配置


        $defaults = [
            'allow_redirects' => RedirectMiddleware::$defaultSettings,
            'http_errors'     => true,
            'decode_content'  => true,
            'verify'          => true,
            'cookies'         => false
        ];
        $defaults['proxy']['http']
        $defaults['proxy']['https']
        $defaults['proxy']['no']
        $defaults['cookies']

配置有这么多选项, 

'verify' => false  没有起效

但是 用

解决办法

$client = new \GuzzleHttp\Client(['http_errors' => false]);

就不用返回错误了

/**
     * Middleware that throws exceptions for 4xx or 5xx responses when the
     * "http_error" request option is set to true.
     *
     * @return callable Returns a function that accepts the next handler.
     */
    public static function httpErrors()
    {
        return function (callable $handler) {
            return function ($request, array $options) use ($handler) {
                if (empty($options['http_errors'])) {
                    return $handler($request, $options);
                }
                return $handler($request, $options)->then(
                    function (ResponseInterface $response) use ($request, $handler) {
                        $code = $response->getStatusCode();
                        if ($code < 400) {
                            return $response;
                        }
                        throw RequestException::create($request, $response);
                    }
                );
            };
        };
    }

我们来看下源码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值