Answer the question
In order to leave comments, you need to log in
PHP Curl Bad Request JSON - problem in message - how to format correctly?
there is a date array that is passed to be sent via curl to a function
$arData = [
"NAME" => 'Название конференции',
"CODE" => "",
"START" => '18.04.19 11:11:10',
];
telegramNotificationSend($id, $typeNotification, $arData);
$textNotification = " Конференция " . $arData["NAME"] . " скоро начнется. Время начала в " . $arData["START"];
$textNotification = $dateStart . " Конференция скоро начнется. Время начала в ";
$data_string = json_encode ($data, JSON_UNESCAPED_UNICODE);
$curl = curl_init(TELEGRAM_BOT_URL);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
// Принимаем в виде массива. (false - в виде объекта)
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'key: ' . TELEGRAM_BOT_KEY,
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($curl);
curl_close($curl);
Answer the question
In order to leave comments, you need to log in
Issue resolved:
1) encode json without JSON_UNESCAPED_UNICODE
2) add charset=utf-8 to header
$data_string = json_encode ($data);
'Content-Type: application/json; charset=utf-8',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question