【问题标题】:PHP Curl proxy option in Laravel Http FacadeLaravel Http Facade 中的 PHP Curl 代理选项
【发布时间】:2021-09-13 06:20:42
【问题描述】:

我正在使用 Laravel 的 Http 门面发出请求,例如

Http::withHeaders(['user-agent' => 'My User agent'])->retry(3, 500)->get('https://example.com')->body();

并且需要使用代理,在PHP的curl的情况下,根据代理提供者的示例应该这样设置

curl_setopt($curl, CURLOPT_PROXY, 'aaa');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'xxx:xxx');

这些代理选项可以通过上面的 Laravel 的 Http 类来设置吗?

【问题讨论】:

    标签: php laravel curl guzzle


    【解决方案1】:

    Http Facade 允许你使用guzzle options,guzzle 有proxy option。所以根据你的代码,你需要这样做:

    Http::withHeaders(['user-agent' => 'My User agent'])
    ->withOptions(['proxy' => 'http://username:password@192.168.16.1:8080'])
    ->retry(3, 500)
    ->get('https://example.com')
    ->body();
    

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 2021-08-21
      • 2014-12-25
      • 1970-01-01
      • 2020-04-13
      • 2010-12-11
      • 1970-01-01
      相关资源
      最近更新 更多