I'm right now using the Mymemory translation API with API. I keep on getting a lot of errors it doesn't work. I do get a HTTP failed error with file_get_contents.
I use this code:
$text = filter_input(INPUT_GET, 'text');
$from = filter_input(INPUT_GET, 'from');
$to = filter_input(INPUT_GET, 'to');
$url = 'http://mymemory.translated.net/api/get?q=' . $text . '&langpair=' . $from . '|' . $to . '&de=SOMEEMAIL';
$curl = curl_init ($url);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$output = curl_exec ($curl);
If I var_dump
the $curl
variable, I get this: resource(2) of type (curl)
.
If I var_dump
the $output
variable, I get this:
string(90) "<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
"
If I var_dump
the curl_error
function, I get this: string(0) ""
If I var_dump
the curl_errno
function, I get this: int(0)
I got my errors turned on and it doesn't give me any errors with error_reporting either. I don't know what I'm doing. I'm testing by the way through my xampp server localhost first.
I tried using https://
except of http://
but didn't change anything. If I use the url directly as $.get
, it does work. I don't know what I'm doing wrong.
Solved thanks to @Passerby:
Had to use urlencode
over the params:
$text = urlencode(filter_input(INPUT_GET, 'text'));
$from = urlencode(filter_input(INPUT_GET, 'from'));
$to = urlencode(filter_input(INPUT_GET, 'to'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.