0

我正在使用 PerfectSwift 作为 RESTful API 来连接我们的 TeamCity 构建服务器和 HipChat;但是我被困在一个点上,我无法使用 Perfect 的 cURL 包装器发布到 HipChat 后端。

我试图模仿的命令是:

curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>

我目前在我的完美程序中有以下代码:

let curl = CURL(url: "https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>")
curl.setOption(CURLOPT_POST, int: 1)
curl.setOption(CURLOPT_POSTFIELDS, s: "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}")
curl.setOption(CURLOPT_HTTPHEADER, s: "[Content-Type:application/json]")
curl.perform { (code, header, body) in

}

但是,消息永远不会到达 HipChat,或者,如果它到达,它不是可读格式。

当我将第一个命令粘贴到终端时,一切都按预期工作。

据我了解,这使用了与 PHP 类似的系统,因此我将 PHP 标记包括在内,因为我觉得如果我使用错误的 CURLOPT 等,PHP 开发人员可能能够提供建议......

提前致谢。

4

0 回答 0