<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HTTP Event Collector 400 Bad Request in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331570#M93459</link>
    <description>&lt;P&gt;You are missing a lot of the expected fields for a JSON HEC event. Such as index, sourcetype, host, source etc as metadata then your event data should be in a field called event.  I don't know .net but here is example in python.  It should give you idea on building your JSON to post. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/georgestarcher/Splunk-Class-httpevent"&gt;https://github.com/georgestarcher/Splunk-Class-httpevent&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jan 2018 20:21:48 GMT</pubDate>
    <dc:creator>starcher</dc:creator>
    <dc:date>2018-01-23T20:21:48Z</dc:date>
    <item>
      <title>HTTP Event Collector 400 Bad Request</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331569#M93458</link>
      <description>&lt;P&gt;I am sending a request to Splunk using .NET code which returns a response of (400) Bad Request.&lt;BR /&gt;
The bytes are seen as received by Splunk in the log file http_event_collector_metrics however there seems to be some parsing error flag getting set "num_of_parser_errors":1.  The index search does not show any data being received. &lt;/P&gt;

&lt;P&gt;Similar request using the same token is working with Python. What could be the problem in below .NET code ?&lt;/P&gt;

&lt;P&gt;Code is as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class Program
{
    static void Main(string[] args)
    {
        WebRequest request = WebRequest.Create("http://localhost:8088/services/collector/event");
        request.ContentType = "application/json";
        request.Method = "POST";
        request.Headers.Add("Authorization", "Splunk 6d8a53cd-eb65-4a1d-abb9-6dc8ad01e616");

        string strjson = "{\"QUEUE\":\"STARTED\"," +
              "\"STATUS\":\"SUCCESS\"}";

        try
        {

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {

                streamWriter.Write(strjson);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)request.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                System.Diagnostics.Debug.WriteLine("Data sent to splunk...." );
                System.Diagnostics.Debug.WriteLine(result);
            }

        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine(e);
        }

    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note the&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:49:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331569#M93458</guid>
      <dc:creator>KP2018</dc:creator>
      <dc:date>2020-09-29T17:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP Event Collector 400 Bad Request</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331570#M93459</link>
      <description>&lt;P&gt;You are missing a lot of the expected fields for a JSON HEC event. Such as index, sourcetype, host, source etc as metadata then your event data should be in a field called event.  I don't know .net but here is example in python.  It should give you idea on building your JSON to post. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://github.com/georgestarcher/Splunk-Class-httpevent"&gt;https://github.com/georgestarcher/Splunk-Class-httpevent&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 20:21:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331570#M93459</guid>
      <dc:creator>starcher</dc:creator>
      <dc:date>2018-01-23T20:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP Event Collector 400 Bad Request</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331571#M93460</link>
      <description>&lt;P&gt;With Python it is already working for me as mentioned in my original query. Need to know how to work with .NET&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 07:46:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331571#M93460</guid>
      <dc:creator>KP2018</dc:creator>
      <dc:date>2018-01-29T07:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP Event Collector 400 Bad Request</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331572#M93461</link>
      <description>&lt;P&gt;Ok have solved it the problem with DotNet code was with the JSON string. Changing it to below solved the problem.&lt;/P&gt;

&lt;P&gt;string strjson = "{ \"event\": \"{QUEUE:STARTED,STATUS:SUCCESS}\"}";&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 07:23:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/HTTP-Event-Collector-400-Bad-Request/m-p/331572#M93461</guid>
      <dc:creator>KP2018</dc:creator>
      <dc:date>2018-01-30T07:23:42Z</dc:date>
    </item>
  </channel>
</rss>

