Created
May 19, 2020 20:49
-
-
Save weeksdev/e66f4bf44a98db078681b87644e5d87b to your computer and use it in GitHub Desktop.
Manual http request to splunk event collector
This file contains 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
WebRequest request = WebRequest.Create("https://splunkserver/services/collector"); | |
request.Method = "POST"; | |
request.Headers.Add("Authorization", "Splunk YOUR_GUID"); | |
ASCIIEncoding encoding = new ASCIIEncoding(); | |
var requestBody = JsonConvert.SerializeObject(new | |
{ | |
@event = new | |
{ | |
FirstName = "Foo", | |
LastName = "Bar" | |
}, | |
host = Environment.MachineName, | |
source = "YOUR_DIRECTORY" | |
}); | |
byte[] bytes = encoding.GetBytes(requestBody); | |
request.ContentLength = bytes.Length; | |
using (var stream = request.GetRequestStream()) | |
{ | |
stream.Write(bytes, 0, bytes.Length); | |
} | |
using (var response = request.GetResponse()) | |
using (var stream = response.GetResponseStream()) | |
{ | |
var contents = new StreamReader(stream).ReadToEnd(); | |
Console.WriteLine(contents); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment