Guzzle x Curl

249 views
Skip to first unread message

Elvis Perpetuo dos Reis

unread,
Jan 30, 2017, 12:18:54 PM1/30/17
to Guzzle - PHP HTTP client and REST client framework
I'm migrating some of my script that I use the curl for guzzle class plus I'm not getting the right setup right.

The return of the pages are different

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.walmart.com.br/placa-de-video-pny-geforce-gt-610-vcggt6102xpb-s-2gb-ddr3/2795035/pr');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$html = curl_exec($curl);
curl_close($curl);
?>

<?php
require "../vendor/autoload.php";

use GuzzleHttp\Client;

$client = new Client();
try {
    $response = $client->get('https://www.walmart.com.br/placa-de-video-pny-geforce-gt-610-vcggt6102xpb-s-2gb-ddr3/2795035/pr', [
        'curl' => [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HEADER => false
        ]
    ]);
    $html = $response->getBody()->getContents();
}
catch (GuzzleHttp\Exception\ClientException $e) {
    $response = $e->getResponse();
    $responseBodyAsString = $response->getBody()->getContents();
}
?>
Reply all
Reply to author
Forward
0 new messages