Basic Requests

Let’s start with a basic request.

<?php
$client = new Zend_Http_Client; $client->setUri('http://localhost.example');
$response = $client->request();

// This does the same thing
$client = new Zend_Http_Client('http://localhost.example'); $response = $client->request('GET');

// Another way to set the request method $client->setMethod(Zend_Http_Client::GET); ?>
  • The URL for the request can either be passed as the first parameter to the Zend_Http_Client constructor or via the setUri method after the client instance is created. Both methods accept the URI as either a string or an instance of Zend_Uri_Http.
  • The request method of the client is used to dispatch the request, taking an optional parameter of a string containing the HTTP request method to use. GET is used by default. The HTTP request method can also be set via the client setMethod method using the client class constant named for that HTTP request method.

© Zend_Http_Client — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (01.09.2014)
Views: 343 | Rating: 0.0/0
Total comments: 0
avatar