Skip to content

Instantly share code, notes, and snippets.

@raul782
Created October 29, 2012 18:29
Show Gist options
  • Save raul782/3975502 to your computer and use it in GitHub Desktop.
Save raul782/3975502 to your computer and use it in GitHub Desktop.
guzzle 404
<?php require_once(__DIR__.'/../../vendor/autoload.php');
use Guzzle\Http\Client;
use Guzzle\Common\Event;
use Guzzle\Http\Message\Request;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\BadResponseException;
$url = 'http://www.amazon.com';
$client = new Client($url);
$client->getEventDispatcher()->addListener('request.error', function(Event $event) {
if ($event['response']->getStatusCode() == 404) {
$newResponse = new Response($event['response']->getStatusCode());
$event['response'] = $newResponse;
$event->stopPropagation();
}
});
$uri = 'XX';
$request = $client->get('/'.$uri);
$response = $request->send();
echo $uri.'::'.$response->getStatusCode();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment