1
我有一个web服务,可以很好地处理get请求,但尝试使用post似乎并不奏效。我有这个在我的路线:Cakephp向webservice发送请求
Router::connect("/products/service_add", array("controller"=>"products", "action" => "service_add", 'seller'=>true, "[method]" => "POST"));
卖方就像一个管理员。我也有ParseExtensions('xml')。我的操作是:
function seller_service_add() {
$this->log("hit", 'debug');
$hi = array("message"=>"hey");
$this->set(compact('hi'));
}
和观点是:
<product>
<?php echo $xml->serialize($hi); ?>
</product>
当我尝试后发送到API我只是得到一个调试跟踪回来计时器信息。在我正在做post请求的同一个脚本中,我正在做一个get,当我运行脚本时,我可以看到API传递给get的数据,但不是post请求。
我使用发送后的代码是:
$ch = curl_init();
$data = array('Your' => 'Data');
curl_setopt($ch, CURLOPT_URL, "http://localhost/<project>/products/service_add.xml");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);`
为什么这是行不通的任何想法?任何帮助将非常感激。
对不起,如果这有点冗长!
更新:我添加了一些行来将事件吐出到cakephp调试日志中,当操作被击中时。我在beforeFilter上有一个条目,这个条目被打到,我可以在日志中看到它。 service_add动作中的条目不存在于日志中,所以我猜动作没有被击中?
说实话,我不知道,我还以为它序列化的数据?无论哪种方式,我只是没有http_build_query尝试它,它仍然无法正常工作! – chvck 2011-04-06 17:43:29