CURL and Zend_Http
It’s a well know fact that you can preform HTTP requests with CURL. Zend Framework does the same job with Zend_Http. Especially Zend_Http_Client can be used to “replace” the usual client – the browser, and to perform some basic requests.
I’ve seen mostly GET requests, although Zend_Http_Client can perform various requests such as POST as well.
// new HTTP request to some HTTP address $httpClient = new Zend_Http_Client('http://www.example.com/'); // GET the response $response = $httpClient->request(Zend_Http_Client::GET); |
Here’s a little snippet showing how to POST some data to a server.
// new HTTP request to some HTTP address $client = new Zend_Http_Client('http://www.example.com/'); // set some parameters $client->setParameterPost('name', 'value'); // POST request $response = $client->request(Zend_Http_Client::POST); |
Note that the request method returns a response. Thus if you are simulating a form submit action you can “redirect” to the desired page just like the form.
// new HTTP request to some HTTP address $client = new Zend_Http_Client('http://www.example.com/'); // set some parameters $client->setParameterPost('name', 'value'); // POST request $response = $client->request(Zend_Http_Client::POST); echo $response->location; |