title: How do post a search string to google.com using c#?
body: <p>Here is my code</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Net;
  using System.Text;
  
  namespace Examples.System.Net
  {
      public class Program
      {
          public static void Main ()
          {
  </code></pre>
  
  <p>// Create a request using a URL that can receive a post. </p>
  
  <pre><code>            WebRequest request = WebRequest.Create("http://www.google.com");
  </code></pre>
  
  <p>// Set the Method property of the request to POST.</p>
  
  <pre><code>            request.Method = "POST";
  </code></pre>
  
  <p>// Create POST data and convert it to a byte array.</p>
  
  <pre><code>           string postData = "This is a test that posts this string to a Web server.";
             byte[] byteArray = Encoding.UTF8.GetBytes (postData);
  </code></pre>
  
  <p>// Set the ContentType property of the WebRequest.</p>
  
  <pre><code>           request.ContentType = "application/x-www-form-urlencoded";
  </code></pre>
  
  <p>// Set the ContentLength property of the WebRequest.</p>
  
  <pre><code>           request.ContentLength = byteArray.Length;
  </code></pre>
  
  <p>// Get the request stream.</p>
  
  <pre><code>           Stream dataStream = request.GetRequestStream ();
  </code></pre>
  
  <p>// Write the data to the request stream.</p>
  
  <pre><code>           dataStream.Write (byteArray, 0, byteArray.Length);
  </code></pre>
  
  <p>// Close the Stream object</p>
  
  <pre><code>           dataStream.Close ();
  </code></pre>
  
  <p>// Get the response.</p>
  
  <pre><code>           WebResponse response = request.GetResponse ();
  </code></pre>
  
  <p>// Display the status.</p>
  
  <pre><code>           Console.WriteLine (((HttpWebResponse)response).StatusDescription);
  </code></pre>
  
  <p>// Get the stream containing content returned by the server.</p>
  
  <pre><code>           dataStream = response.GetResponseStream ();
  </code></pre>
  
  <p>// Open the stream using a StreamReader for easy access.</p>
  
  <pre><code>           StreamReader reader = new StreamReader (dataStream);
  </code></pre>
  
  <p>// Read the content.</p>
  
  <pre><code>           string responseFromServer = reader.ReadToEnd ();
  
  // Display the content.
  
             Console.WriteLine (responseFromServer);
  
  // Clean up the streams.
  
             reader.Close ();
             dataStream.Close ();
             response.Close ();
         }
      }
  }
  </code></pre>
  
  <p>This is the exception I am getting</p>
  
  <pre><code>Unhandled Exception: System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
         at System.Net.HttpWebRequest.GetResponse()
         at Examples.System.Net.Program.Main()
  </code></pre>