Tag Archives: Cross-site request forgery

Send Authenticated POST Request with Zend_Http_Client


There is an easy way to send requests with Zend_Http_Client either in GET and POST. Actually you can request not only with GET and POST methods, but with any other http request method.

$httpClient = new Zend_Http_Client('http://....');
// request via post
$response = $httpClient->request(Zend_Http_Client::POST);
// or get
$response = $httpClient->request(Zend_Http_Client::GET);

However the interesting and useful thing is that you can perform authenticated requests:

$httpClient = new Zend_Http_Client('http://username:password@example.com');
// or define it later
$httpClient = new Zend_Http_Client('http://example.com');
$httpClient->setAuth('username', 'password');

That’s an opportunity to send/receive authenticated POST requests.

$httpClient = new Zend_Http_Client('http://username:password@example.com');
// now post
$httpClient->request(Zend_Http_Client::POST);