如何使用POST方法进行Google翻译。我不想出于某种原因使用JS,需要用PHP来做。以下不起作用。
public static function googleTranslatePost($text = "What are you looking at", $destLang='fr', $srcLang = 'en')
{
$http_response = '';
$ch = curl_init('http://translate.google.com/translate_t');
curl_setopt($ch, CURLOPT_POSTFIELDS,'hl=en&ie=UTF8&text=-->this+is+a+test<--&langpair=en%7Car');
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$http_response = curl_exec($ch);
return $http_response;
}