I looked through all of the other terminal vs. PHP questions and couldn't find a solve.
I'm working with data API and this works to retrieve a list of files:
What am I missing in the translation?
PHP CODE:
$url = 'https://api-url';
$data = array(
'header' => array(
'id' => '1',
),
'others' => array(
"details" => yes,
),
);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
var_dump($result);
Terminal code:(Working fine)
curl -X POST -d '{"header": {"id": 1}, "others": {"details": yes}' --user "u-p" 'https://api-url'