-
-
Save huglester/5082390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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