Last active
March 13, 2018 13:27
-
-
Save ryanhoskin/e8308f823f0eb62ab241 to your computer and use it in GitHub Desktop.
Trigger a PagerDuty incident in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
namespace Examples.System.Net | |
{ | |
public class WebRequestPostExample | |
{ | |
public static void Main() | |
{ | |
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://events.pagerduty.com/generic/2010-04-15/create_event.json"); | |
httpWebRequest.ContentType = "application/json"; | |
httpWebRequest.Method = "POST"; | |
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) | |
{ | |
string json = "{\"service_key\":\"ENTER_YOUR_SERVICE_API_KEY_HERE\"," + | |
"\"event_type\":\"trigger\"," + | |
"\"description\":\"heyo\"}"; | |
streamWriter.Write(json); | |
streamWriter.Flush(); | |
streamWriter.Close(); | |
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); | |
using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) | |
{ | |
var result = streamReader.ReadToEnd(); | |
Console.WriteLine(result); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment