以下是我打电话的行动:
public function request_add(){
// remotely post the information to the server
$link = "http://" . $_SERVER['HTTP_HOST'] . $this->webroot.'rest_events.json';
$data = null;
$httpSocket = new HttpSocket();
$data['Event']['customer_id'] = '107';
$data['Event']['user_id'] = '124';
$data['Event']['date'] = '2014-07-12';
$data = array('Event'=>'id');
$response = $httpSocket->post($link, $data );
$this->set('response_code', $response->code);
$this->set('response_body', $response->body);
$this -> render('/Client/request_add');
}
在这种情况下,链接是:http://localhost/application/rest_events.json
问题是发出了GET请求而不是POST,我得到的是事件列表。
以前有人遇到过这样的问题吗?
我期待听到一些意见。
更新
在调试http请求时,我发现发出了POST请求而不是GET。这是对象:
array(
'method' => 'POST',
'uri' => array(
'host' => '*****',
'port' => '*****',
'scheme' => 'http',
'user' => null,
'pass' => null,
'path' => '/application/rest_events.json',
'query' => array(),
'fragment' => null
),
'version' => '1.1',
'body' => 'Event%5Bcustomer_id%5D=107&Event%5Buser_id%5D=124&Event%5Bdate%5D=2014-07-12',
'line' => 'POST /application/rest_events.json HTTP/1.1
',
'header' => 'Host: localhost
Connection: close
User-Agent: CakePHP
Content-Type: application/x-www-form-urlencoded
Content-Length: 76
',
'raw' => 'POST /application/rest_events.json HTTP/1.1
Host: localhost
Connection: close
User-Agent: CakePHP
Content-Type: application/x-www-form-urlencoded
Content-Length: 76
Event%5Bcustomer_id%5D=107&Event%5Buser_id%5D=124&Event%5Bdate%5D=2014-07-12',
'redirect' => false,
'cookies' => array(),
'proxy' => array(),
'auth' => array()
)
但仍然会调用index()
操作而不是add()
。所以问题在于路由。我是对的吗?