I have this error:
Parameter 1 passed to Symfony\Component\HttpFoundation\Request::__construct() must be the given array or string type, in C:\xampp\htdocs\satusehat2\app\Http\Controllers\ PasienController calls .php line 68.
This is my function
public function curl_postman() { $client = new Client(); $headers = [ 'Content-Type' => 'application/json', 'Authorization' => 'My Bearer token' ]; $body = ''; $request = new Request('GET', 'my-api-address', $headers, $body); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); }
Line 68 is
$body = '';
You can use
Symfony\Component\HttpFoundation\Request::create()
instead, which implicitly calls the request factory and returns aRequest
object.PS: There is no need to explicitly specify the
method
parameter, because'GET'
is the default value.