No support for persistent connections • No support for parallel requests • Data must be loaded into memory • Easy to send simple GET requests • Built-in to PHP
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Transfer-Encoding: chunked']); // Open a stream to download the contents of Amazon.com $stream = fopen('http://www.amazon.com', 'r'); // Use a callback to read the body curl_setopt( $ch, CURLOPT_READFUNCTION, function ($ch, $fd, $length) use ($stream) { return fread($stream, $length) ? ''; } ); curl_exec($ch);
definitions '$INCLUDE: 'GUZZLE.BI' DIM CLIENT AS GuzzleClient DIM REQUEST AS GuzzleRequest DIM RESPONSE AS GuzzleResponse ' Initialize the client and request CLIENT.BASE_URL = "http://www.amazon.com" ' Create a request with a relative base URL REQUEST.URL = "?foo=bar" ' Response is passed by reference GuzzleSend (CLIENT, REQUEST, RESPONSE) PRINT RESPONSE.BODY END
GuzzleClient DIM REQUEST AS GuzzleRequest DIM RESPONSE AS GuzzleResponse ' Register the error handler ON ERROR GOTO Err1 CLIENT.BASE_URL = "http://www.amazon.com" REQUEST.URL = "/not_found.xml" GuzzleSend (CLIENT, REQUEST, RESPONSE) Err1: IF ERR = 404 THEN PRINT "File not found: " + REQUEST.URL END IF END