Reputation: 10241
I'm trying to call a web service on a clients server using the Guzzle library - but the server have a proxy so I'm getting a 404 error in my code.
If I ssh into the clients server and try
wget http://www.mywebsite.com/mywebservice
I get an error
Resolving proxy.theirdomainname.com (proxy.theirdomainname.com)... xx.xx.xx.xx
Connecting to proxy.theirdomainname.com (proxy.theirdomainname.com)|xx.xx.xx.xx|:80...
failed: Connection timed out.
But if I use
wget --no-proxy http://www.mywebsite.com/mywebservice
I get a result
Resolving www.mywebsite.com (www.mywebsite.com)... xx.xx.xx.xx
Connecting to www.mywebsite.com (www.mywebsite.com)|xx.xx.xx.xx|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
I can see an option to set the proxy in the Guzzle documentation - http://guzzle.readthedocs.org/en/latest/http-client/client.html#proxy
But how do I disable using a proxy altogether? Or will this be a server setting?
EDIT:
$request = $client->get($this->url(), array('proxy' => ''))
->setHeader('Accept', 'text/xml');
$response = $request->send();
var_dump($response);
Result :
Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException'
with message 'Client error response [status code] 404 [reason phrase] Not Found [url] http://mywebsite.com'
in /vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php:44
Stack trace: #0 /guzzle/guzzle/src/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Response))
#1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event))
#2 /vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Guzzle\Common\Event))
#3 /vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(53): Symfony in /vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php on line 44
Upvotes: 2
Views: 8182
Reputation: 961
If you are using Guzzlehttp6 :
if you want to specify a different proxy for a given type of protocol :
$client->request('GET', 'your_url_here', [
'proxy' => [
'http' => 'tcp://localhost:8125', // Use this proxy with "http"
'https' => 'tcp://localhost:9124', // Use this proxy with "https",
'no' => ['.mit.edu', 'foo.com'] // Don't use a proxy with these
]
]);
If you want to disable proxy for all your queries :
$client->request('GET','your_url_here',['proxy'=>'']);
Upvotes: 6
Reputation: 1947
It's because Guzzle\Client
auto-magically sets the proxy looking at your system environment variables. It doesn't matter if you're on Linux or Windows:
280: // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set
281: if ($proxy = getenv('HTTP_PROXY')) {
282: $settings['proxy']['http'] = $proxy;
283 }
284
285: if ($proxy = getenv('HTTPS_PROXY')) {
286: $settings['proxy']['https'] = $proxy;
287 }
So if you previously set your proxy using something like
set HTTP_PROXY=http://your.proxy.local:8080
set HTTPS_PROXY=http://your.proxy.local:8080
then this proxy setting will be picked up.
You have to enforce an empty proxy like Marcell Fülöp said.
Upvotes: 1