我有这样的错误:
传递给 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 = '';
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以使用
Symfony\Component\HttpFoundation\Request::create()来代替,它隐式调用请求工厂并返回Request对象。PS:不需要显式指定
method参数,因为'GET'是默认值。