参数1传递给SymfonyComponentHttpFoundationRequest::__construct(



我有这个错误说:

参数1传递给SymfonyComponentHttpFoundationRequest::__construct()必须是数组类型,字符串给定,在C:xampphtdocssatusehat2appHttpControllersPasienController.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 = '';

您可以使用SymfonyComponentHttpFoundationRequest::create()代替,它隐式调用请求工厂并返回一个Request对象。

$request = Request::create(uri: 'my-api-address', content: $body, server: $headers)

PS:method参数不需要显式指定,'GET'为默认值。

最新更新