Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mymemory translate API-CURL不工作_Php_Curl - Fatal编程技术网

Php Mymemory translate API-CURL不工作

Php Mymemory translate API-CURL不工作,php,curl,Php,Curl,我现在正在使用Mymemory转换API和API。我不断地犯很多错误,但它不起作用。我确实收到了一个关于文件内容的HTTP失败错误 我使用以下代码: $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=' . $t

我现在正在使用Mymemory转换API和API。我不断地犯很多错误,但它不起作用。我确实收到了一个关于文件内容的HTTP失败错误

我使用以下代码:

$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);
如果我
var\u dump
这个
$curl
变量,我得到这个:
类型为(curl)
的资源(2)

如果我
var\u dump
这个
$output
变量,我会得到:

string(90) "<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
"
string(90)“400错误请求
您的浏览器发送了无效的请求。
"
如果我
var\u dump
使用
curl\u error
函数,我会得到这个:
string(0)“

如果我
var\u dump
使用
curl\u errno
函数,我会得到以下结果:
int(0)

我打开了我的错误,它也不会给我任何错误报告。我不知道我在做什么。我首先通过我的xampp服务器localhost进行顺便测试


除了
http://
之外,我尝试使用了
https://
,但没有改变任何东西。如果我直接使用url作为
$.get
,它确实有效。我不知道我做错了什么。

多亏了@Passerby:

必须在参数上使用
urlencode

$text = urlencode(filter_input(INPUT_GET, 'text'));
$from = urlencode(filter_input(INPUT_GET, 'from'));
$to = urlencode(filter_input(INPUT_GET, 'to'));

你有
urlencode
d所有参数吗?哦,我没有。。。现在开始工作了,谢谢!