Запрос PHP для ретрансляции

пишу код и понадобилась интеграция с Discord Webhook.

Если я выдаю POST запрос с параметрами на PHP скрипт, то у меня ничего не происходит, помогите пожалуйста. (Причина в PHP скрипте)

Тестовая часть запроса из html в PHP:

function sendMessage() {
var request = new XMLHttpRequest();
request.open("POST", "http://{сайт}/index.php");

  request.setRequestHeader('Content-type', 'application/json');

  var params = {
    username: "My Webhook Name",
    avatar_url: "",
    content: "The message to send"
  }
request.send(JSON.stringify(params));
}

PHP скрипт не рабочий:

<?php
$postData = file_get_contents('php://input');
$data = json_decode($postData, true);
$hoks = json_encode( $data );
// Replace the URL with your own webhook url
$url = "{WEBHOOK}";

$ch = curl_init();
$hoks = json_encode( $_POST['JSON'] );
curl_setopt_array( $ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hoks,
CURLOPT_HTTPHEADER => [
    "Content-Type: application/json"
]
]);

$response = curl_exec( $ch );
curl_close( $ch );

?>

Ответы (0 шт):