I have this error that says:
Argument 1 passed to Symfony\Component\HttpFoundation\Request::__construct() must be of the type array, string given, called in C:\xampp\htdocs\satusehat2\app\Http\Controllers\PasienController.php on 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();
}
and the line 68 is
$body = '';
CodePudding user response:
You can use Symfony\Component\HttpFoundation\Request::create()
instead which implicitly calls a request factory and returns you a Request
object.
$request = Request::create(uri: 'my-api-address', content: $body, server: $headers)
PS: You do not need to explicitly specify the method
parameter as 'GET'
is the default value.