What is the difference between
$HttpSocket->post('http://localhost:8090/example/samplecontroller/add', $data);
and
$this->redirect(array('controller'=>'samplecontroller','action' => 'add', $data));
Both post the data ,whereas first method is not working for me. I used
App::uses('HttpSocket', 'Network/Http'); and
$HttpSocket = new HttpSocket();
How to make it work? Or The second method is also HTTPpost?
Edited
public function httppost() {
App::uses('HttpSocket', 'Network/Http');
$HttpSocket = new HttpSocket();
$data = array('name' => 'test', 'type' => 'user');
$response = $HttpSocket->post('http://localhost:8090/catv/airtime_masters/httpget', $data);
return $response;
}
public function httpget() {
debug($this->request->data);
exit;
}
when i run httpget() i get array()
I dont think they both POST the data, Im pretty sure redirect will send the data as GET method.. or as url vars eg(?parameter1=value1¶meter2=value2).
They are quite different. redirect is used when you want the user to sent to another page. The HTTPSocket->Post method is used when you want to post some data to a URL and do something with the response eg:
$response = $HttpSocket->post('http://localhost:8090/example/samplecontroller/add', $data);
/** do something with $response data here **/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.