我正在使用curl調用API方法(Symfony2,FOSRestBundle)並想知道如何獲取POSTFIELDS中發送的數據?PHP - 如何使用CURL發送POSTFIELDS?
$_params = [];
$data_string = json_encode($_params);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $_method);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$json = curl_exec($curl);
如果我在例如CURLOPT_HTTPHEADER送東西,我可以在以後使用控制器
$request->headers->get("some_variable");
得到它,但我怎麼能訪問$ data_string?我已經甩了幾乎每一個可能的變量,仍然沒有:)
THX :)
這是正確的,但我需要讓所有POST變量與CURL一起發送。 我的意思是我需要retrevie變量$ data_string的值。 – Durian
@Durian我已經更新了我的答案。 –
我已經更新了一點我的問題。我的問題是,我需要訪問控制器中的$ data_string變量,當$ _params是一個數組(有時是空的,有時包含一些鍵和值) – Durian