【问题标题】:How can I send an API Request directly from Controller in Laravel 5.2?如何在 Laravel 5.2 中直接从 Controller 发送 API 请求?
【发布时间】:2016-06-19 18:36:27
【问题描述】:

我目前正在从事一个在多个网站上实现 API 集成的项目。

随着我的进展,我注意到我在我的项目中使用了过多的 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 

        }

    }

【问题讨论】:

    标签: php jquery ajax api laravel-5.2


    【解决方案1】:

    您可以使用 Guzzle https://github.com/guzzle/guzzle 库来发出 HTTP 请求。

    【讨论】:

    • 谢谢伙计。我会逐一调查。
    猜你喜欢
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 2015-10-12
    • 2011-09-20
    • 1970-01-01
    • 2019-07-19
    • 2016-11-27
    相关资源
    最近更新 更多