Installation

Why am I getting this 400 Bad Request?

lrs122
New Member

I've tried about 80 different variations on this payload, but can't get anything to work. The below is probably the most simplistic with nothing but a "*" in the search. All return a 400 Bad Request. I'm sure it's something simple (always is) and I've re-read the documentation a couple times, so hopefully someone here can smack me in the back of the head. This is a Linqpad script, BTW.

void Main()
{
    var data = "search=\"*\"";
    var url = "https://gannett.splunkcloud.com:8089/services/search/jobs";
    var userName = "username";
    var passWord = "password";
    var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + passWord));

    HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
    webRequest.ContentType = "text/plain";
    webRequest.Method = "POST";
    webRequest.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
    using (var dataStream = webRequest.GetRequestStream())
    {
        var content = Encoding.UTF8.GetBytes(data);
        dataStream.Write(content, 0, content.Length);
    }

    var responseBody = string.Empty;
    try
    {
        IgnoreBadCertificates();
        var webResponse = (HttpWebResponse)webRequest.GetResponse();
        using (var responseStream = webResponse.GetResponseStream())
        {
            var streamReader = new StreamReader(responseStream);
            responseBody = streamReader.ReadToEnd();
            Console.WriteLine(responseBody);
        }
    }
    catch (Exception exception)
    {
        Console.WriteLine(exception.Message);
        Console.WriteLine(responseBody);
    }

}

public static void IgnoreBadCertificates()
{
    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
} 
private static bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
    return true;
} 
Tags (2)
0 Karma
Get Updates on the Splunk Community!

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco + Splunk! We’ve ...