我有這樣的錯誤:
傳遞給Symfony\Component\HttpFoundation\Request::__construct() 的參數1 必須是給定的陣列、字串類型,在C:\xampp\htdocs\satusehat2\app\Http\Controllers\在 PasienController 中呼叫.php 第68 行。
這是我的功能
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(); }
第 68 行是
$body = '';
您可以使用
Symfony\Component\HttpFoundation\Request::create()
來代替,它隱含呼叫請求工廠並傳回Request
物件。PS:不需要明確指定
method
參數,因為'GET'
是預設值。