I would like to create a php form that will send a POST using curl.
My curl
curl-H "Content-Type: application/json" \
-X POST \
-d '{"Id":"1", "CreatedAt":"2020-07-15 09:00:00","CategoryName":"Kategoria1", \
"SubcategoryName":"Podkategoria2","LocationCode":"125", \
"LocationStandCode":"EGZ","ProblemDescription":"Nie włącza się.", \
"TicketParameters":[{"ParameterCode":"Temat","Value":"Problem"}]}' \
http://localhost:8080/api/new
php code not working
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8080/ehelpdesk/api/new');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"Id\":\"2\",\"CreatedAt\":\"2020-07-10 11:32:04\",\"CategoryName\":\"Kategoria1\",\"SubcategoryName\":\"\Podkategoria2}");
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
?>
Do you have any idea what I'm doing wrong?