$inputJSON = file_get_contents('php://input');
if($inputJSON !== null){
$result = json_decode($inputJSON, TRUE);
echo json_encode($result);
}else{
return false;
}
document.addEventListener('DOMContentLoaded', function () {
function UseFetch(requestData = {}) {
console.log('Получили объект', requestData);
console.log("Отправляемый JSON: ", JSON.stringify(requestData));
fetch('/api.php', {
method: 'POST', // or 'PUT'
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestData)
})
.then((result) => result.ok === true ? result.json() : false)
.then((data) => console.log("Success", data))
.catch(error => console.error("Error", error));
}
UseFetch({ 'path': 123, 'abc': 234 });
});
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://fleet-api.taxi.yandex.net/v1/parks/driver-profiles/list');
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '{"query": {"park": {"id": "идентификатор партнера"}}}');
curl_setopt($curl, CURLOPT_HTTPHEADER,
[
'X-Client-ID: taxi/park/token',
'X-API-Key: api_key',
'Accept-Language: en'
]
);
$cont = curl_exec($curl);
$tt = json_decode($cont);