我目前正在从事一个在多个站点上实现API集成的项目。
现在,当我进行的过程中,我注意到我在项目中使用了太多使用 JQuery 的 AJAX 请求(其中代码可在页面源代码上查看),我想尽可能地限制它。
有没有办法直接从Laravel 5.2中的任何控制器发送API请求,就像下面的代码一样?
<?php
namespace App'Http'Controllers;
use Illuminate'Http'Request;
class HttpRequestController extends Controller
{
public function PostRequest($uri, $data) {
//functional code that will post the given data to the specified uri
}
public function GetRequest($uri) {
//functional code that will retrieve the given data via the specified uri
}
}
您可以使用Guzzle
https://github.com/guzzle/guzzle 库发出 HTTP 请求。