how Can i post data to an url using curl and json?
i want to use api of a website for send notification to my app and the website help is not good :/
website said you should write in header of request tokan code and some setting how can i post json data to this website with php ? with these header "Authorization: Token 7fb1………………………………29b464c " "Content-Type: application/json" "Accept: application/json"
and the url is from help text of website curl -X POST "https://panel.pushe.co/api/v1/notifications/"
please help me@_@
从这里的示例
$data = array("name" => "Hagrid", "age" => "36");
$data_string = json_encode($data);
$ch = curl_init('http://api.local/rest/users');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
使用这样的东西:
$ curl -X POST -i -H "Content-Type: application/json" -H "Authorization: TOKEN <YOUR_TOKEN>" https://panel.pushe.co/api/v1/notifications/
上一篇: 从一个分离的头部推动git推动