我在以下代码块中使用cURL发送数据:
$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);
Web服务端确实运行并创建了文件,但$ _POST为空。我只是无法弄清楚原因。
public function action_getAccess() {
file_put_contents('/home/donut/uploads/data.txt', $_POST);
}
答案 0 :(得分:0)
来自卷曲:
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/plain"));
并将其视为:
file_put_contents('/home/donut/uploads/data.txt', file_get_contents("php://input"));