我需要使用example.com中的API 我使用Laravel作为框架,并在他们的文档中使用API获取数据我看到了:
curl https://api.example.com/api/AvailabilitySearch ^
-H "Authorization: Bearer eyJ0ehsagdasjhgdashdgaOiJIUzI1NiJ9.eyJpc3Msjhdshjdasd7676N5c3RlbXMuY29tIn0.DBR5UPxxxxxxzxzxzxzxzxzxzxyzxyzxyzxyzyxzyxyzxyxxWQ_BkS1mzxw" ^
-d VisitDate=2017-05-08 ^
-d PartySize=2 ^
-d ChannelCode=ONLINE
我尝试做的是:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use GuzzleHttp;
class TestController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function test()
{
$client = new GuzzleHttp\Client();
$res = $client->request('GET','https://example.com/api/AvailabilitySearch', [
'headers' => [
'Authorization' => 'Bearer eyJ0ehsagdasjhgdashdgaOiJIUzI1NiJ9.eyJpc3Msjhdshjdasd7676N5c3RlbXMuY29tIn0.DBR5UPxxxxxxzxzxzxzxzxzxzxyzxyzxyzxyzyxzyxyzxyxxWQ_BkS1mzxw',
],
'form_params' => [
'VisitDate' => '2017-05-24',
'PartySize' => '2',
'ChannelCode' => 'ONLINE',
],
]);
// You need to parse the response body
// This will parse it into an array
$res = json_decode($res->getBody(), true);
dd ($res);
}
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
现在,当我尝试测试时,我得到了:
BadMethodCallException in functions.php line 324:
Unknown method, request
我如何解决这个问题?如何使用Guzzle而不是使用Laravel框架的cURL?我的代码有什么问题...我只是关注guzzle文档和API文档。