Unfortunately,
despite the pleasing simplicity of this code the resulting request will fail because Akismet doesn??™t return the
XML response that is expected by Zend_Rest_Client when used this way.
Since all Akismet needs is a simple HTTP request and Zend_Rest itself uses Zend_Http_Client why then
can??™t we just use Zend_Http_Client in the first place? The answer, as demonstrated in listing 11.11, is that we
can.
Listing 11.11 A REST request to Akismet using Zend_Http_Client
$client = new Zend_Http_Client('http://rest.akismet.com/1.1/verify-key'); A
$data = array( B
'key' => 'f6k3apik3y',
'blog' => 'http://places/'
);
$client->setParameterPost($data); C
try {
$response = $client->request(Zend_Http_Client::POST); D
var_dump($response);
} catch (Zend_Http_Client_Exception $e) {
echo $e->getCode() . ': ' . $e->getMessage() . "\n";
}
A Instantiate the client with the URL of the resource
B Build an array with the data required for the verify key request
C Format the data into an HTTP POST
D Make the request (wrapped in a try/catch exception block)
Zend_Http_Client will not attempt to parse the returned response from Akismet as if it was XML and we
will receive the plain text response ???valid??? or ???invalid??? depending on whether our data is verified successfully
or not, respectively.
Pages:
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335