I want to download an image in this page. The image source ishttp://i2.pixiv.net/c/600x600/img-master/img/2015/01/19/12/17/13/48258889_p0_master1200.jpg
. I try to download it use this:
$client = new Goutte\Client ();
$client->getClient->get($img_url, array('save_to' => $img_url_save_name));
But I failed, then I realize if I directly accesshttp://i2.pixiv.net/c/600x600/img-master/img/2015/01/19/12/17/13/48258889_p0_master1200.jpg
, I are denied by CDN nginx server. I have to access this image link in 'www.pixv.net' page, which means my image request reference is 'www.pixv.net'. How to do this in Goutte?
I got the answer:
$client->getClient()->get($img_url, ['save_to' => $img_url_save_name,
'headers'=>['Referer'=>$src]
]);
Actually I can set header Referer in Goutte\Client
and but there's no option to give a path to save image. So I finally use Guzzle Client instead.