How to use proxy authentication with Goutte?
I have the following code but it always returns a 407
HTTP status code.
$url = 'http://whatismyip.org';
$client = new Client();
$options = array(
'proxy' => array(
'http' => 'tcp://@x.x.x.x:8010',
),
'auth' => array('d80fe9ebasab73d21a4', '', 'basic')
);
$crawler = $client->request('GET', $url, $options);
$status = $client->getResponse()->getStatus();
echo $status; // 407
I am using Goutte with Guzzle 6. I started off trying to set the proxy with setDefaultOption
but this method has been deprecated.
My username and blank password is definitely correct as it works with curl
on the command line:
curl -U d80fe9ebasab73d21a4: -vx x.x.x.x:8010 http://whatismyip.org/
I have spent several hours on this and I would appreciate any help!
Solution 1:
Have you tried to instantiate your Client with the proxy options directly?
Like this:
$url = 'http://whatismyip.org';
$client = new Client($url, array(
'version' => 'v1.1',
'request.options' => array(
'auth' => array('d80fe9ebasab73d21a4', '', 'Basic'),
'proxy' => 'tcp://@x.x.x.x:8010'
)
));
$crawler = $client->request('GET', $url);
$status = $client->getResponse()->getStatus();
echo $status; // 407
Solution 2:
$config = [
'proxy' => [
'http' => 'xx.xx.xx.xx:8080'
]
];
$client = new Client($config);
$client->setAuth('username', 'password', 'basic');
$crawler = $client->request('GET', $url);
$status = $client->getResponse()->getStatus();
echo $status;
I suppose it's a client configuration, not a request parameter.