【发布时间】:2013-02-15 10:08:05
【问题描述】:
我已经在 restler 框架中创建了 web 服务,我正在尝试使用 curl 从我创建的客户端库中的 php 中插入数据。
api.php
/**
* Manually routed method. we can specify as many routes as we want
*
* @url POST addcomment/{token}/{email}/{comment}/{story_id}
*/
function addComment($token,$email,$comment,$story_id){
return $this->dp->insertComment($token,$email,$comment,$story_id);
}
来自客户端的测试目的:testing.php
$data_string = "token=900150983cd24fb0d6963f7d28e17f72&email=kamal@gmail.com&comment=commentusingcurl&story_id=2";
$ch = curl_init('http://localhost/Restler/public/examples/news/addcomment');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-Type : text","Content-lenght:".strlen($data_string)));
$result = curl_exec($ch);
但它会抛出 404。请帮忙。
【问题讨论】:
-
可能是没有获取到url路径。
-
我正在使用 GET 方法获得成功。
-
嗯,404 只是一个未找到的响应。您是否检查过 URL 是否正确?在浏览器或命令行中尝试。
-
所以使用
GET如果它工作正常。:)
标签: php web-services curl restler