문제

I'm sending data using cURL on the following code block:

$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);

The webservice side do run and creates the file, but $_POST is empty. I just can't figure out why.

public function action_getAccess() {
    file_put_contents('/home/donut/uploads/data.txt', $_POST);
}
도움이 되었습니까?

해결책

From curl:

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

And catch this as:

file_put_contents('/home/donut/uploads/data.txt', file_get_contents("php://input"));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top