T
T
TommyAngel2018-03-20 14:33:29
PHP
TommyAngel, 2018-03-20 14:33:29

Can't send PUT data to API using Curl method. How to implement?

It is necessary to send the data using the PUT method. I wrote this script. It seems there are no errors, but the record is not added. Tell me where is the mistake?

// логин и пароль
$server = "https://site/api/task/64651";
$login = "...";
$password = ".";
$params = array(
   'Comment' => '1',
   'IsPrivateComment' => '1'
);
$paramsdata = json_encode($params);
// авторизация
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);       
curl_setopt($ch, CURLOPT_USERPWD, $login . ":" . $password); 
// Отправляю

curl_setopt($ch, CURLOPT_URL,"$server");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($paramsdata)));
curl_setopt($ch, CURLOPT_PUT, true);
//отправляю
curl_exec ($ch);
curl_close ($ch);

PUT /api/task/taskid
where taskid is the ID of the task to be changed
Fields to change:
Comment type String
IsPrivateComment type bool (as I understand it, you need 1 to activate)
I googled hundreds of sites, I can't find what's wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hardcorelite, 2018-03-20
@TommyAngel

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

T
TommyAngel, 2018-03-20
@TommyAngel

How to transfer data? I don't understand Curl at all... Dear pros, help me)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question