title: Delphi: Using Google URL Shortener with IdHTTP - 400 Bad Request
body: <p>I'm trying to access the URL Shortener ( <a href="http://goo.gl/" rel="nofollow">http://goo.gl/</a> ) via its API from within Delphi.
  However, the only result I get is: <strong>HTTP/1.0 400 Bad Request (reason: parseError)</strong></p>
  
  <p>Here is my code (on a form with a <em>Button1</em>, <em>Memo1</em> and <em>IdHTTP1</em> that has <em>IdSSLIOHandlerSocketOpenSSL1</em> as its IOHandler. I got the necessary 32-bit OpenSSL DLLs from <a href="http://indy.fulgan.com/SSL/" rel="nofollow">http://indy.fulgan.com/SSL/</a> and put them in the .exe's directory):</p>
  
  <pre><code>procedure TFrmMain.Button1Click(Sender: TObject);
      var html, actionurl: String;
      makeshort: TStringList;
  begin
  try
   makeshort := TStringList.Create;
  
   actionurl := 'https://www.googleapis.com/urlshortener/v1/url';
   makeshort.Add('{"longUrl": "http://slashdot.org/stories"}');
  
   IdHttp1.Request.ContentType := 'application/json';
   //IdHTTP1.Request.ContentEncoding := 'UTF-8'; //Using this gives error 415
  
   html := IdHTTP1.Post(actionurl, makeshort);
   memo1.lines.add(idHTTP1.response.ResponseText);
  
       except on e: EIdHTTPProtocolException do
          begin
              memo1.lines.add(idHTTP1.response.ResponseText);
              memo1.lines.add(e.ErrorMessage);
          end;
      end;
  
   memo1.Lines.add(html);
   makeshort.Free;
  end;
  </code></pre>
  
  <p><em>Update:</em> I have left off my API key in this example (should usually work well without one for a few tries), but if you want to try it with your own, you can substitute the <em>actionurl</em> string with
      <code>'https://www.googleapis.com/urlshortener/v1/url?key=&lt;yourapikey&gt;';</code></p>
  
  <p>The ParseError message leads me to believe that there might be something wrong with the encoding of the longurl when it gets posted but I wouldn't know what to change.</p>
  
  <p>I've been fuzzing over this for quite a while now and I'm sure the mistake is right before my eyes - I'm just not seeing it right now.
  Any help is therefore greatly appreciated!</p>
  
  <p>Thanks!</p>