我已經在restler框架中創建了webservices,我試圖在我創建的客戶端lib中使用curl在curl中插入數據。如何在PHP中使用Curl進行POST數據?
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 protected]&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);
但它拋出。請幫忙。
可能是它沒有得到url路徑。 – 2013-02-15 10:12:25
我正在使用GET方法獲得成功。 – 2013-02-15 10:14:47
那麼,404只是一個沒有找到答案。你是否檢查過該網址是否正確?在瀏覽器中或從命令行嘗試它。 – Clyde 2013-02-15 10:15:29