有什么区别
$HttpSocket->post('http://localhost:8090/example/samplecontroller/add', $data);
和
$this->redirect(array('controller'=>'samplecontroller','action' => 'add', $data));
两者都发布数据,而第一种方法对我不起作用。 我用过
App::uses('HttpSocket', 'Network/Http'); and
$HttpSocket = new HttpSocket();
如何让它发挥作用?或者第二种方法也是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;
}
当我运行 httpget() 时,我得到 array()
最佳答案
我不认为他们都发布了数据,我很确定重定向会将数据作为 GET 方法发送。
它们完全不同。当您希望用户发送到另一个页面时使用重定向。 HTTPSocket->Post 方法用于将一些数据发布到 URL 并对响应执行某些操作,例如:
$response = $HttpSocket->post('http://localhost:8090/example/samplecontroller/add', $data);
/** do something with $response data here **/
关于http - CakePHP 中的 http post 和 Redirect 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36767531/