如何使用PHP Gout发送Cookie
我在PHP Goutte中有这段代码如何使用PHP Gout发送Cookie,php,curl,cookies,goutte,Php,Curl,Cookies,Goutte,我在PHP Goutte中有这段代码 $client = new GuzzleHttp\Client([ 'base_uri' => 'http://www.yellowpages.com.au', 'cookies' => true, 'headers' => [ 'Accept' => 'text/html,application/xhtml+xml,application/x
$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发送到服务器
通常我用简单的卷曲来做
$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);
我在古特的某个地方看到了这件事
$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
试试这个:
$client = new \GuzzleHttp\Client(array(
'curl' => array(
CURLOPT_COOKIEFILE => $cookie_file,
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_RETURNTRANSFER => 1
),
'cookies' => true
));
这对我来说是一个很大的帮助: