I need to use and API from example.com I use Laravel as a framework and to get data with API in their docs I see this:
curl http://ift.tt/2riu0gD ^
-H "Authorization: Bearer eyJ0ehsagdasjhgdashdgaOiJIUzI1NiJ9.eyJpc3Msjhdshjdasd7676N5c3RlbXMuY29tIn0.DBR5UPxxxxxxzxzxzxzxzxzxzxyzxyzxyzxyzyxzyxyzxyxxWQ_BkS1mzxw" ^
-d VisitDate=2017-05-08 ^
-d PartySize=2 ^
-d ChannelCode=ONLINE
What I try to do is:
<?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','http://ift.tt/2rRzzj0', [
'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)
{
//
}
}
Now when I try to test i get:
BadMethodCallException in functions.php line 324:
Unknown method, request
How I can solve ths problem? How to use Guzzle instead cURL with Laravel framework? What is wrong in my code ... I just follow guzzle docs and API docs.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire