Reputation: 57926
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!
Upvotes: 10
Views: 3625
Reputation: 1322
In new version you should use like this.
$config = ['proxy' => host:port];
$client = new Client(HttpClient::create($config));
Remember to mentions
use Symfony\Component\HttpClient\HttpClient;
use Goutte\Client;
Basically a client configuration needed.
Upvotes: 1
Reputation: 1048
$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.
Upvotes: 1
Reputation: 1396
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
Upvotes: 1