Laravel Http Client请求https

jiang 发表于2020-03-27 19:32:02 最后修改于2025-01-22 11:37:18 18307

laravel7 HTTP Client 如何请求https网址

//代码如下 网址做了马赛克
$response = \Http::get('https://example.com');

报错如下

GuzzleHttp\Exception\RequestException cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

CURLE_PEER_FAILED_VERIFICATION (60)

The remote server's SSL certificate or SSH md5 fingerprint was deemed not OK. This error code has been unified with CURLE_SSL_CACERT since 7.62.0. Its previous value was 51.

方法一(永久)禁用https验证就行
找到vendor\guzzlehttp\guzzle\src\Client.php 下的 configureDefaults方法,把verify修改为false

private function configureDefaults(array $config)
{
  $defaults = [
    'allow_redirects' => RedirectMiddleware::$defaultSettings,
    'http_errors'     => true,
    'decode_content'  => true,
    //'verify'          => true,
    'verify'          => false,//禁用https验证
    'cookies'         => false
  ];
  .....
}

方法二 请求时加上withoutVerifying方法如下

$response = \Http::withoutVerifying()->get('https://example.com');

详细方法在 vendor\laravel\framework\src\Illuminate\Http\Client\PendingRequest.php中


wumiantu 2020-11-18 14:55:02
头像
这是关于阳光体育的吗 回复
jiang 2020-11-18 14:58:44
头像
@wumiantu 不是,只是个人博客😂 回复
wumiantu 2020-11-18 15:06:20
头像
@jiang 我看你那个阳光体育的代跑做的不错,有开源吗 回复
jiang 2020-11-18 19:07:54
头像
@wumiantu 网上开源代码挺多的,一搜就能搜到😶 回复
头像

jiang

积土而为山,积水而为海。

Copyright © 2017-2020 嘉丽谷 版权所有