【问题标题】:Guzzle using proxy to requestGuzzle 使用代理请求
【发布时间】:2015-08-31 11:18:19
【问题描述】:

我想在 guzzle 中请求页面时使用代理。下面的代码遇到了警告:

Warning: curl_setopt_array(): Array keys must be CURLOPT constants or equivalent integer values in .../guzzle/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 56 
Warning: curl_setopt_array(): Array keys must be CURLOPT constants or equivalent integer values in .../guzzle/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 56
Warning: curl_setopt_array(): Array keys must be CURLOPT constants or equivalent integer values in .../guzzle/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 56
cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Run-time warning: curl_setopt_array(): Array keys must be CURLOPT constants or equivalent integer values in .../guzzle/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 56

这段代码有什么问题:

this->method = 'GET';
$this->request = new Request($this->method, $this->url);
$this->options = [
'base_uri'     => $this->base_uri,
'timeout'      => 30,
'curl'  => [
        'CURLOPT_PROXY' => '*.*.*.*',
        'CURLOPT_PROXYPORT' => 80,
        'CURLOPT_PROXYUSERPWD' => '*:*',
   ],
'headers' => [
        'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36'
   ]
];
$this->response = $this->send($this->request, $this->options);// $this extends Client Class

【问题讨论】:

    标签: php curl guzzle


    【解决方案1】:

    刚刚在尝试解决我遇到的代理相关问题时发现了这个问题,但这似乎很容易解决。

    在错误信息中:

    运行时警告:curl_setopt_array():数组键必须是 CURLOPT 常量或等效整数值

    在您的代码中:

    'curl'  => [
        'CURLOPT_PROXY' => '*.*.*.*',
        'CURLOPT_PROXYPORT' => 80,
        'CURLOPT_PROXYUSERPWD' => '*:*',
    ],
    

    您已经制作了常量字符串,因此它们不会作为有效键传递。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2017-11-19
      • 2020-07-14
      • 2018-02-07
      • 2017-08-28
      • 2014-09-22
      • 2019-12-17
      相关资源
      最近更新 更多