# 基本
curl http://httpbin.org/get
# リクエストメソッド追加 -X GET, -X POST
curl -X GET "http://httpbin.org/get"
curl -X POST "http://httpbin.org/post"
# ヘッダ変更 -H
## accept を追加
curl -X POST "http://httpbin.org/post" -H "accept: application/json"
# コンテンツ変更 -X POST -d
$ curl -H "content-type: application/json" -X POST -d'{"asa_gohan":"misosiru", "oyatsu":"karl"}' http://httpbin.org/post
#
# エラーを吐く -f
curl -f -X POST "http://httpbin.org/status/400" -H "accept: text/plain"
完成パターン(bash)
# 1
curl -H 'Authorization: Bearer xoxp-962856939590-1752215539557-2243792265904-1a13a103b2bb3b38486c925b3bfc37f4' -H 'Content-Type: application/json; charset=utf-8' -XPOST -d '{"channel":"#test2","post_at":1624944450,"text":"Hello Wold"}' https://slack.com/api/chat.scheduleMessage
# 2
curl -XPOST 'https://slack.com/api/chat.scheduleMessage' -H 'Authorization: Bearer xoxp-962856939590-1752215539557-2243792265904-1a13a103b2bb3b38486c925b3bfc37f4' -H 'Content-Type: application/json; charset=utf-8' --data-binary '{"channel":"#test2","post_at":1624945800,"text":"Hello Wold"}'
# 3
curl -XPOST 'https://slack.com/api/chat.scheduleMessage' -H 'Authorization: Bearer xoxp-962856939590-1752215539557-2243792265904-1a13a103b2bb3b38486c925b3bfc37f4' -H 'Content-Type: application/json; charset=utf-8' -d '{"channel":"#test2","post_at":1624945800,"text":"Hello Wold"}'
完成パターン(php)
<?php
define('SLACK_WEBHOOK', 'https://slack.com/api/chat.scheduleMessage');
for($i = 1; $i < 10 ;$i++)
{
$timer = time() + 10;
$message = '{"channel":"#test2","post_at":' . $timer .',"text":"' . 'hello ' . $i .'"}';
$headers = array(
'Authorization: Bearer xoxp-962856939590-1752215539557-2243792265904-1a13a103b2bb3b38486c925b3bfc37f4',
'Content-Type: application/json',
'charset: utf-8');
$c = curl_init(SLACK_WEBHOOK);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $message);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_exec($c);
curl_close($c);
}
?>
↧