title: 400 bad request in google translate free api using curl
body: <p>I am trying to use free Google Translate API which is extracted from Firefox's S3 Google Translator addon, ie.</p>
  
  <pre><code>https://translate.google.com/translate_a/single?client=t&amp;sl=auto&amp;
  tl=en&amp;hl=en&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=qca&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t
  &amp;dt=at&amp;ie=UTF-8&amp;oe=UTF-8&amp;otf=2&amp;srcrom=1&amp;ssel=0&amp;tsel=0&amp;q=Hello
  </code></pre>
  
  <p>in PHP cURL ie.</p>
  
  <pre><code>$isPOST=isset($_POST) &amp;&amp; !empty($_POST);
  $q=$isPOST ? $_POST['q'] : $_GET['q'];
  
  $url='https://translate.google.com/translate_a/single';
  $data='client=t&amp;sl=auto&amp;tl=en&amp;hl=en&amp;dt=bd&amp;dt=ex&amp;dt=ld&amp;dt=md&amp;dt=qca&amp;dt=rw&amp;dt=rm&amp;dt=ss&amp;dt=t&amp;dt=at&amp;ie=UTF-8&amp;oe=UTF-8&amp;otf=2&amp;srcrom=1&amp;ssel=0&amp;tsel=0&amp;q='.$q;
  $ch=curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_NOBODY, 0);
  curl_setopt($ch, CURLOPT_URL, !$isPOST ? $url.'?'.$data : $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_REFERER, $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  if($isPOST){
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  }
  $return=curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p>I am calling this page using ajax..</p>
  
  <pre><code>$.ajax({
      type: text.length&gt;750 ? 'post' : 'get',
      url: 'translate.php',
      data: 'q='+text,
      success: function(d){ alert(d); }
  });
  </code></pre>
  
  <p>but doing this all, I get this response from Google Translate, ie.</p>
  
  <pre><code>Error: 400. That’s an error.
  Your client has issued a malformed or illegal request. That’s all we know.
  </code></pre>
  
  <p>Please, help me solve this error and get the translated text..</p>