title: calling google Url Shortner API in C#
body: <p>I want to call the <a href="http://code.google.com/apis/urlshortener/v1/getting_started.html" rel="nofollow noreferrer">google url shortner API</a> from my C# Console Application, the request I try to implement is:</p>
  
  <blockquote>
    <p>POST <a href="https://www.googleapis.com/urlshortener/v1/url" rel="nofollow noreferrer">https://www.googleapis.com/urlshortener/v1/url</a></p>
    
    <p>Content-Type: application/json</p>
    
    <p>{"longUrl": "<a href="http://www.google.com/" rel="nofollow noreferrer">http://www.google.com/</a>"}</p>
  </blockquote>
  
  <p>When I try to use this code:</p>
  
  <pre><code>using System.Net;
  using System.Net.Http;
  using System.IO;
  </code></pre>
  
  <p>and the main method is:</p>
  
  <pre><code>static void Main(string[] args)
  {
      string s = "http://www.google.com/";
      var client = new HttpClient();
  
      // Create the HttpContent for the form to be posted.
      var requestContent = new FormUrlEncodedContent(new[] {new KeyValuePair&lt;string, string&gt;("longUrl", s),});
  
      // Get the response.            
      HttpResponseMessage response = client.Post("https://www.googleapis.com/urlshortener/v1/url",requestContent);
  
      // Get the response content.
      HttpContent responseContent = response.Content;
  
      // Get the stream of the content.
      using (var reader = new StreamReader(responseContent.ContentReadStream))
      {
          // Write the output.
          s = reader.ReadToEnd();
          Console.WriteLine(s);
      }
      Console.Read();
  }
  </code></pre>
  
  <p>I get the error code 400: This API does not support parsing form-encoded input.
  I don't know how to fix this.</p>