<?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: Why is remote server returning error: (400) Bad Request trying to run a search macro using C#? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125221#M33837</link>
    <description>&lt;P&gt;Update: - I have looked at the examples provided in the SDK but those are all console app related&lt;/P&gt;</description>
    <pubDate>Mon, 15 Sep 2014 19:54:43 GMT</pubDate>
    <dc:creator>rajakanapala</dc:creator>
    <dc:date>2014-09-15T19:54:43Z</dc:date>
    <item>
      <title>Why is remote server returning error: (400) Bad Request trying to run a search macro using C#?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125220#M33836</link>
      <description>&lt;P&gt;I am trying to run a search ( Macro) but I am not able to get past this error "The remote server returned an error: (400) Bad Request."&lt;/P&gt;

&lt;P&gt;Here are my requirements -&lt;/P&gt;

&lt;P&gt;1) Run this search ( most efficient way using C#.NET)&lt;BR /&gt;
2) Get the output in XML &lt;BR /&gt;
3) And then I would like to parse this XML and store the results in my local database&lt;/P&gt;

&lt;P&gt;I am quite new to splunk, any help would be greatly appreciated &lt;/P&gt;

&lt;P&gt;I am using C# and I also want to know if there is a better way of doing this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;        // connection info
        var connectArgs = new ServiceArgs
        {
            Host = ConfigurationManager.AppSettings["SplunkHost"],
            Port = Convert.ToInt16(ConfigurationManager.AppSettings["Port"])
        };

        // Create new Service object
        Service service = new Service(connectArgs);

        // Use the Login method to connect
        service.Login(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]);        

        var mySearch = "`investigate(ipaddress,\"9/11/2014:10:40:0\",\"9/11/2014:10:45:0\",\"\")`";            

        var job = service.GetJobs().Create(mySearch);

        // Wait for the job to finish
        while (!job.IsDone)
        {
            Thread.Sleep(500);
        }

        // Create a UTF-8 encoding
        UTF8Encoding utf8 = new UTF8Encoding();

        // Display results
        var results = job.Results();
        String line = null;
        System.Console.WriteLine("Results from the search job as XML:\n");
        StreamReader sr = new StreamReader(results, utf8);
        while ((line = sr.ReadLine()) != null)
        {
            Response.Write(line);
        }

        sr.Close();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Sep 2014 19:22:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125220#M33836</guid>
      <dc:creator>rajakanapala</dc:creator>
      <dc:date>2014-09-15T19:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why is remote server returning error: (400) Bad Request trying to run a search macro using C#?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125221#M33837</link>
      <description>&lt;P&gt;Update: - I have looked at the examples provided in the SDK but those are all console app related&lt;/P&gt;</description>
      <pubDate>Mon, 15 Sep 2014 19:54:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125221#M33837</guid>
      <dc:creator>rajakanapala</dc:creator>
      <dc:date>2014-09-15T19:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why is remote server returning error: (400) Bad Request trying to run a search macro using C#?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125222#M33838</link>
      <description>&lt;P&gt;Even i am also facing the same issue. Any updates ?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 16:03:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125222#M33838</guid>
      <dc:creator>ma7859</dc:creator>
      <dc:date>2015-12-08T16:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why is remote server returning error: (400) Bad Request trying to run a search macro using C#?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125223#M33839</link>
      <description>&lt;P&gt;I got the solution.&lt;BR /&gt;
We need to pass our splunk search starting with search .&lt;BR /&gt;
Hope this helps someone.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 17:18:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-remote-server-returning-error-400-Bad-Request-trying-to/m-p/125223#M33839</guid>
      <dc:creator>ma7859</dc:creator>
      <dc:date>2015-12-08T17:18:08Z</dc:date>
    </item>
  </channel>
</rss>

