10

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!

Abs
  • 56,052
  • 101
  • 275
  • 409
  • This may happen when a client tries to use HTTP1 instead of HTTP1.1 -- curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); Not sure how the client works on the inside .. check your curl version – DannyZB Oct 09 '15 at 17:01
  • Hard to say. Use Wireshark to inspect request on network layer. Also check that you have enabled cURL extension in your PHP and Guzzle uses CurlHandler. Why do you have `@` char before proxy IP? You can also try as proxy address something like this `http://d80fe9ebasab73d21a4@x.x.x.x:8010` and omit `auth` option. – kba Oct 13 '15 at 08:10
  • @Abs : How did you solve proxy issue . can you let me know ? – 06011991 Jun 12 '17 at 07:20

3 Answers3

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
Dennis Stücken
  • 1,296
  • 9
  • 10
  • Stucken : This solution is not working for me . its returning the my local system ip instead of proxy IP . can you suggest some solution for this ? – 06011991 Jun 12 '17 at 07:22
1
$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.

Michele Carino
  • 1,043
  • 2
  • 11
  • 25
1

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.

Jnanaranjan
  • 1,304
  • 15
  • 31