This project is read-only.

Secure search fails


I am trying to perform a secure search from the C#.Net code.The search fails with a 417:Expectation failed error. I am also sending the default network credentials from my code.
It works fine when I perform the secure search from the google interface.

SSL Settings->Force secure connections when serving? ->The following option is selected.
Use HTTPS when serving secure results, but not when serving public results.

I can also see the current SSL certificate information in GSA.

Serving Logs:

I can see the query request given from my .Net app in the log.The log ends after redirecting the authentication to SAML.Is there anything additional to be sent along with the request other than the user credentials?
My search URL looks like this:

My SecureSearch function looks like this.

private string PerformSecureSearch(string googleSearchURL)
        Uri contentURL;
        HttpWebRequest webRequest;
        HttpWebResponse webResponse;
        Stream responseStream;
        StreamReader streamReader;
        string searchResults = "";
       int i = 0;


            contentURL = new Uri(googleSearchURL);

            // Create a new web request
            webRequest = (HttpWebRequest)WebRequest.Create(contentURL);
          webRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            webRequest.Method = "GET";

            //Trust all certificate
            System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
            System.Net.ServicePointManager.Expect100Continue = false;

            // Invoke the web request and get the response back via HTTP
            webResponse = (HttpWebResponse)webRequest.GetResponse();

            // Get the XML response back and pass the data back "as-is".
            responseStream = webResponse.GetResponseStream();
            streamReader = new StreamReader(responseStream);
            searchResults = streamReader.ReadToEnd();
        catch (WebException ex)
            _errorOccurred = true;

            // Throw the exception so that the calling application can handle it
            throw (ex);
        catch (Exception ex)
            _errorOccurred = true;

            // Throw the exception so that the calling application can handle it
            throw (ex);

        return searchResults;

Can you please provide with a working C# implementation for secure search?