我正在尝试为hipchat房间创建卷曲通知,它生成的通知令牌仅适用于该房间。
curl -d '{"color":"green","message":"My first notification
(yey)","notify":false,"message_format":"text"}' -H 'Content-Type:
application/json' <My URL and TOKEN GO HERE>
我的代码:
<?php
$payload = array("message"=>"testing");
print_r($payload);
$json = json_encode($payload,true);
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "my url with token"
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
$ch = curl_exec ($curl);
curl_close ($curl);
print_r($ch);
?>
我得到了这个结果:
Array
(
[message] => testing
)
{
"error": {
"code": 400,
"field": "message",
"message": "Required field 'message' is missing",
"type": "Bad Request",
"validation": "optional",
"value": null
}
我尝试了https://github.com/hipchat/hipchat-php和https://github.com/rcrowe/Hippy,但他们需要管理员API令牌。
谢谢, IJC
答案 0 :(得分:1)
您需要像在命令行中一样发送Content-Type
标题和curl请求,或者后端不知道如何解析数据。
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));