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;
ecgo $response->getBody();
If you want to send Authenticated POST Request with Zend_Http_Client, then you need to add the following parameter.
$client->setAuth('test_usernaem', 'test_password', Zend_Http_Client::AUTH_BASIC);
original post
No comments:
Post a Comment