donglang8008 2015-08-31 11:18
浏览 1139

Guzzle使用代理请求

I want to use proxy when request for a page in guzzle. The code below encountered with a warning:

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

What is the problem with this code:

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
  • 写回答

1条回答 默认 最新

  • doukekui0914 2016-01-27 13:29
    关注

    Just found this while trying to fix a proxy related issue I was having, but this seems an easy fix.

    In the error message:

    Run-time warning: curl_setopt_array(): Array keys must be CURLOPT constants or equivalent integer values

    In your code:

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

    You have made the constants strings, so therefore they do not pass as valid keys.

    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛