Jump to content

[SOLVED] using cURL to post to a form on GOOGLE


dsaba

Recommended Posts

Hello I need help trying to post to a google form

the url of the form is here:

http://google.com/translate_t

 

There are a couple hidden input types, but the only two which are user filled in are

'text' and 'langpair'

 

the hidden fields are 'hl' and 'ie', tried posting all and only posting the non-hidden ones

I keep getting a google error page of illegal access or error, which means its has not been successfully been posted too

Can anyone help me post successfully to this form with cURL or tell me what i'm doing wrong?-thanks

 

here's what I did with php:

<?php
// create a new curl resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://google.com/translate_t");

// Do a POST
$text = 'hello';
//$data = array('text' => $text, 'langpair' => 'en|ar', 'hl' => 'en', 'ie' => 'UTF8');
$data = array('text' => $text, 'langpair' => 'en|ar');

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// grab URL, and print
curl_exec($ch);
?>

  • 2 months later...

$url = "http://translate.google.com/translate_t";

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 4);

$postdata="hl=en&ie=UTF8&langpair=en|".$lang."&text=".$text;
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);

$result= curl_exec ($ch);
curl_close ($ch);

 

This works, However, this has a problem also... the utf8 does not display properly on foreing languages...

Any help?

 

Using

 

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','Accept-Charset: UTF-8')); 

 

Results in a error.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.