Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending request through sock5 proxy not working #1165

Closed
jitendrar opened this issue Jul 8, 2015 · 8 comments
Closed

Sending request through sock5 proxy not working #1165

jitendrar opened this issue Jul 8, 2015 · 8 comments

Comments

@jitendrar
Copy link

I am trying to send request through my local installed TOR proxy. It is working fine with my simple PHP CURL request with below two curl options setting. But through guzzle it is returning http status code 404 and also not got response properly.

$guzzle = new GuzzleClient(['base_url' => ['webtolife.com/ps.php', []],],
array('curl.options' => array(
'CURLOPT_PROXY' => $tor,
'CURLOPT_PROXYTYPE' => 'CURLPROXY_SOCKS5',
)
)
);
$client->setClient($guzzle);

Can someone please help me to solve this problem. I am trying to solve this since last 3 days but not able to solve.

@mtdowling
Copy link
Member

Which version of Guzzle are you using?

@jitendrar
Copy link
Author

I am using Goutte. And basically Goutte using Guzzle for scraping.
From: Michael Dowling notifications@github.com
To: guzzle/guzzle guzzle@noreply.github.com
Cc: jitendrar jitu_rathod_ld@yahoo.com
Sent: Wednesday, 8 July 2015 10:39 PM
Subject: Re: [guzzle] Sending request through sock5 proxy not working (#1165)

Which version of Guzzle are you using?—
Reply to this email directly or view it on GitHub.

@mtdowling
Copy link
Member

I need to know specifically which version of Guzzle you are using. Maybe show me your composer.json or something.

@jitendrar
Copy link
Author

My composer.json shows "guzzlehttp/guzzle": ">=4,<6"
-------------------------------{    "name": "fabpot/goutte",    "type": "application",    "description": "A simple PHP Web Scraper",    "keywords": ["scraper"],    "homepage": "https://github.com/FriendsOfPHP/Goutte",    "license": "MIT",    "authors": [        {            "name": "Fabien Potencier",            "email": "fabien@symfony.com"        }    ],    "require": {        "php": ">=5.4.0",        "symfony/browser-kit": "~2.1",        "symfony/css-selector": "~2.1",        "symfony/dom-crawler": "~2.1",        "guzzlehttp/guzzle": ">=4,<6"    },    "autoload": {        "psr-4": { "Goutte\": "Goutte" }    },    "extra": {        "branch-alias": {            "dev-master": "2.0-dev"        }    }}--------------------------------------------------------
From: Michael Dowling notifications@github.com
To: guzzle/guzzle guzzle@noreply.github.com
Cc: jitendrar jitu_rathod_ld@yahoo.com
Sent: Saturday, 11 July 2015 1:35 AM
Subject: Re: [guzzle] Sending request through sock5 proxy not working (#1165)

I need to know specifically which version of Guzzle you are using. Maybe show me your composer.json or something.—
Reply to this email directly or view it on GitHub.

@jitendrar
Copy link
Author

More Info in this.

I am getting this error when I try to overwrite the curl option using below code.

$guzzle = $client->getClient();
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_PROXY, $tor);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
$client->setClient($guzzle);

Error I am getting

Exception: cURL error 7: See http://curl.haxx.se/libcurl/c/libcurl-errors.html in [phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php, line 49]
2015-07-13 10:59:00 Error: [GuzzleHttp\Exception\ConnectException] cURL error 7: See http://curl.haxx.se/libcurl/c/libcurl-errors.html
Stack Trace:
#0 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/guzzle/src/RequestFsm.php(104): GuzzleHttp\Exception\RequestException::wrapException(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Ring\Exception\ConnectException))
#1 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/guzzle/src/RequestFsm.php(132): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#2 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/react/promise/src/FulfilledPromise.php(24): GuzzleHttp\RequestFsm->GuzzleHttp{closure}(Array)
#3 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/react/promise/src/Promise.php(114): React\Promise\FulfilledPromise->then(Object(Closure), NULL)
#4 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/react/promise/src/Promise.php(156): React\Promise\Promise->React\Promise{closure}(Object(React\Promise\FulfilledPromise))
#5 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/react/promise/src/Promise.php(128): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#6 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/react/promise/src/Promise.php(169): React\Promise\Promise->resolve(Array)
#7 [internal function]: React\Promise\Promise->React\Promise{closure}(Array)
#8 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/react/promise/src/Deferred.php(35): call_user_func(Object(Closure), Array)
#9 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/ringphp/src/Client/CurlMultiHandler.php(247): React\Promise\Deferred->resolve(Array)
#10 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/ringphp/src/Client/CurlMultiHandler.php(136): GuzzleHttp\Ring\Client\CurlMultiHandler->processMessages()
#11 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/ringphp/src/Future/BaseFutureTrait.php(118): GuzzleHttp\Ring\Client\CurlMultiHandler->execute()
#12 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/ringphp/src/Future/BaseFutureTrait.php(55): GuzzleHttp\Ring\Future\FutureArray->invokeWait()
#13 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/ringphp/src/Future/BaseFutureTrait.php(118): GuzzleHttp\Ring\Future\FutureArray->wait()
#14 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/ringphp/src/Future/BaseFutureTrait.php(55): GuzzleHttp\Message\FutureResponse->invokeWait()
#15 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/guzzlehttp/guzzle/src/Client.php(243): GuzzleHttp\Message\FutureResponse->wait()
#16 phar:///var/www/public_html/vendor/goutte/goutte.phar/Goutte/Client.php(130): GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))
#17 phar:///var/www/public_html/vendor/goutte/goutte.phar/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php(327): Goutte\Client->doRequest(Object(Symfony\Component\BrowserKit\Request))
#18 /var/www/public_html/src/Shell/ScrapShell.php(86): Symfony\Component\BrowserKit\Client->request('GET', '/p...', Array)
#19 [internal function]: App\Shell\ScrapShell->main()
#20 /var/www/public_html/vendor/cakephp/cakephp/src/Console/Shell.php(391): call_user_func_array(Array, Array)
#21 /var/www/public_html/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(204): Cake\Console\Shell->runCommand(Array, true)
#22 /var/www/public_html/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(175): Cake\Console\ShellDispatcher->_dispatch()
#23 /var/www/public_html/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(126): Cake\Console\ShellDispatcher->dispatch()
#24 /var/www/public_html/bin/cake.php(33): Cake\Console\ShellDispatcher::run(Array)
#25 {main}

@jitendrar
Copy link
Author

Yes, But same is working if I use curl directly to send my request without fail.

".CURLOPT_PROXYTYPE."<============>".CURLPROXY_SOCKS5."<=====>".CURLOPT_PROXY."<===="; //The URL to which to POST the data curl_setopt($ch, CURLOPT_URL, $url); //Execute $result = curl_exec($ch); curl_close($ch);    // Closing cURL return $result;   // Returning the data from the function}?>
  From: Kamil Samigullin notifications@github.com

To: guzzle/guzzle guzzle@noreply.github.com
Cc: jitendrar jitu_rathod_ld@yahoo.com
Sent: Monday, 13 July 2015 4:43 PM
Subject: Re: [guzzle] Sending request through sock5 proxy not working (#1165)

I see that this is curl-level error.
CURLE_COULDNT_CONNECT (7)
Failed to connect() to host or proxy.

Reply to this email directly or view it on GitHub.

@jitendrar
Copy link
Author

I have did changes like below and now its working fine. :)

$guzzle = $client->getClient();
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_PROXY, 'socks5://127.0.0.1:9050');
$client->setClient($guzzle);

thanks all for your help on this and also for nice library.

@kamilsk
Copy link
Contributor

kamilsk commented Jul 13, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants