我在PHP Goutte中有这段代码
$client = new GuzzleHttp\Client([
'base_uri' => 'http://www.yellowpages.com.au',
'cookies' => true,
'headers' => [
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding' => 'zip, deflate, sdch',
'Accept-Language' => 'en-US,en;q=0.8',
'Cache-Control' => 'max-age=0',
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0'
]
]);
我想将自定义Cookie发送到服务器
通常我这样做是使用简单的cURL
$a_curl_opts = array(
CURLOPT_NOBODY => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_COOKIEFILE => $file_cook,
CURLOPT_COOKIEJAR => $file_cook,
);
curl_setopt_array($curl_init, $a_curl_opts);
我在Goutte看到了这件事要做的事情
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_COOKIEFILE, $file_cook);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_COOKIEJAR, $file_cook);
但我收到了这个错误。
Catchable fatal error: Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given, called in D:\Ampps\www\gum\vendor\guzzlehttp\guzzle\src\Client.php on line 87 and defined in D:\Ampps\www\gum\vendor\guzzlehttp\guzzle\src\Client.php on line 126
答案 0 :(得分:0)
试试这个:
$client = new \GuzzleHttp\Client(array(
'curl' => array(
CURLOPT_COOKIEFILE => $cookie_file,
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_RETURNTRANSFER => 1
),
'cookies' => true
));