Laravel Http Facade 中的 PHP Curl 代理选项

标签 php laravel curl guzzle

我正在使用 Laravel 的 Http facade 来发出如下请求

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 类以某种方式设置吗?

最佳答案

允许您使用 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();

关于Laravel Http Facade 中的 PHP Curl 代理选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66700709/

相关文章:

php - 在 Laravel 5 中添加新的配置文件不起作用

c - 如何用libcurl开发http服务器

javascript - 将选定的值从文本框移动到下拉列表

php - 提高代码的效率和速度?

php - 我想在我的网站上添加一些检测;这些是好的选择吗?

mysql - 使用 __construct 更新模型以限制返回结果

php - 如何从另一个类方法 PHP 中捕获异常

php - Laravel 查询和过滤

curl 错误 1 ​​: Unsupported protocol: https

python - Python 请求中的 CURL -T(--upload-file 等效项)