c# - 如何将此 HipChat curl 帖子转换为 C#?

标签 c# curl hipchat

我正在尝试为 HipChat 创建通知,不幸的是他们的 HipChat-CS ( https://github.com/KyleGobel/Hipchat-CS ) nuget 包不起作用。因此,我想研究如何手动发送通知,但他们的示例使用的是我不熟悉的 cURL。我想以他们的例子为例,并将其变成我可以在我的 c# 应用程序中使用的东西。任何帮助将不胜感激!下面是 cURL 示例:

curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://organization.hipchat.com/v2/room/2388080/notification?auth_token=authKeyHere

再次感谢!

阿杰

最佳答案

您可以使用 HttpWebRequest 建立连接并发送您的 json 负载。您需要将 System.Net 添加到您的使用指令中。

string jsonContent = "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}";
byte[] jsonBytes = Encoding.ASCII.GetBytes(jsonContent);
var request = (HttpWebRequest) WebRequest.Create("https://organization.hipchat.com/v2/room/2388080/notification?auth_token=authKeyHere");
request.ContentType = "application/json";
request.Method = "POST";
request.ContentLength = jsonBytes.Length;

using (var reqStream = request.GetRequestStream())
{
    reqStream.Write(jsonBytes, 0, jsonBytes.Length);
    reqStream.Close();
}

 WebResponse response = request.GetResponse();
//access fields of response in order to get the response data you're looking for.

关于c# - 如何将此 HipChat curl 帖子转换为 C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38618492/

相关文章:

ruby - 如何通过 API 从 Hipchat 获取房间的所有消息历史记录?

c# - 有更好的设计选择吗?

c# - Emgu C#中的空引用异常

php - 使用 FB Graph API 获取所有 Facebook 群组帖子

macos - 是否可以将 curl 设置为在进度条之前显示文件名?

c++ - 使用 cURLpp 进行多次下载的进度指示器

c# - 我可以将 Windows (.bat) 文件放入 Visual Studio C# 项目的资源文件夹中吗?

c# - 仅在函数内初始化值一次

python - Nagios - 通过 Hipsaint 集成 Hipchat

html - Hubot 可以向 Hipchat 发送 HTML 或其他类型的格式化消息吗?