Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.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 如何在控制器函数中调用API_Php_Laravel_Get - Fatal编程技术网

Php 如何在控制器函数中调用API

Php 如何在控制器函数中调用API,php,laravel,get,Php,Laravel,Get,我在controller中有一个函数,我想调用一个HTTP请求传递url,比如AJAX中的GET请求,但我不知道如何使用php使用它。我尝试过这个 public function sendAPIRequest() { $url = "https://myapi.com?apikey=".$api."&message=".$message."&receiver=".$receiver; //This is what I tried file_get_cont

我在controller中有一个函数,我想调用一个HTTP请求传递url,比如AJAX中的GET请求,但我不知道如何使用php使用它。我尝试过这个

public function sendAPIRequest()
{
    $url = "https://myapi.com?apikey=".$api."&message=".$message."&receiver=".$receiver;
    //This is what I tried
    file_get_contents($url);
    //But it didn't work
}
你可以用在拉威尔身上


可能是@ThomasSnijder yess的复制品可能是兄弟!谢谢:)我需要什么吗?喜欢作曲的人需要小发明
    $client = new \GuzzleHttp\Client();
$res = $client->request('GET', "https://myapi.com?apikey=".$api."&message=".$message."&receiver=".$receiver);
echo $res->getStatusCode();
// 200
echo $res->getHeaderLine('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// '{"id": 1420053, "name": "guzzle", ...}'