If Zend_Http_Client can successfully make the request surely there is a way that Zend_Rest can do the
same? Of course there is and in listing 11.12, which should be looking familiar by now, we bypass having
Akismet??™s plain text response parsed as XML by calling the restPost() method directly. Unlike our first attempt
this method returns the body of the HTTP response rather than sending it through Zend_Rest_Client_Result.
Listing 11.12 A REST request to Akismet using Zend_Rest
$client = new Zend_Rest_Client('http://rest.akismet.com'); A
$data = array( B
'key' => 'f6k3apik3y',
'blog' => 'http://places/'
);
try {
$response = $client->restPost('/1.1/verify-key', $data); C
var_dump($response);
} catch (Zend_Rest_Client_Exception $e) {
echo $e->getCode() . ': ' . $e->getMessage() . "\n";
}
A Instantiate the client with the URL to make requests to
B Build an array with the data required for the verify key request
C Make the HTTP POST request with the path of the resource and data to verify
Having solved the problem we were having with Akismet??™s service we now know we can use
Zend_Rest_Client with plain text and XML based RESTful web services. If we wanted to work with the rest of
Akismet??™s resources it would obviously make more sense to use Zend_Service_Akismet, but if there was not a
pre-built Zend Framework component we are now aware of several options.
Pages:
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336