我怎样才能使用curl和json将数据发布到URL?
我想使用api的网站发送通知给我的应用程序和网站的帮助不好:/
网站说,你应该写在请求tokan代码的头和一些设置我怎么能张贴JSON数据到这个网站用PHP? 带有这些头文件“Authorization:Token 7fb1 .................................... 29b464c”“Content-Type:application / json”“Accept:application / json”
该网址来自网站curl -X POST的帮助文本“https://panel.pushe.co/api/v1/notifications/”
请帮帮我@_@
从这里的示例
$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/
上一篇: how Can i post data to an url using curl and json?
下一篇: How to send post request with spring @RequestBody in rest client