2017-05-09 82 views
1

我想用於發送通知的網站的API,以我的應用程序 和網站的幫助並不好:/如何使用curl和json將數據發佈到URL?

網站上說,你應該在請求tokan代碼頭寫一些設置 我怎麼能張貼JSON數據到這個網站用PHP? 與這些頭 「授權:令牌7fb1 .................................... 29b464c」 「內容類型:應用/ JSON」 「接受:應用/ JSON」

和URL被從網站 捲曲-X POST 「https://panel.pushe.co/api/v1/notifications/

幫助文本,請幫助我!@ _ @

+0

歡迎堆棧溢出,在未來的問題,請嘗試格式化你的問題更好地(在代碼塊的實例代碼),所以它會更容易閱讀的人。 – Picard

回答

0

PHP例如從here

$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); 
1

使用這樣的事情:

$ curl -X POST -i -H "Content-Type: application/json" -H "Authorization: TOKEN <YOUR_TOKEN>" https://panel.pushe.co/api/v1/notifications/