2014-03-19 37 views
0

我用下面的代碼塊上捲曲發送數據:Kohana的捲曲發送的數據是空的

$content = $data['email'].'|'.$data['limit'].'|'.$data['docs']; 

$curl = curl_init(ACCESS_URL); 
curl_setopt($curl, CURLOPT_HEADER, false); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

$answer = curl_exec($curl); 
curl_close($curl); 

WebService的側做運行,並創建該文件,但$ _ POST是空的。我無法弄清楚爲什麼。

public function action_getAccess() { 
    file_put_contents('/home/donut/uploads/data.txt', $_POST); 
} 

回答

0

從捲曲:

curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/plain")); 

,趕上這個爲:

file_put_contents('/home/donut/uploads/data.txt', file_get_contents("php://input")); 
+0

恰到好處! –