postman 参数1已传递到Symfony\组件\HttpFoundation\请求::__构造()

kx1ctssn  于 2022-12-13  发布在  Postman
关注(0)|答案(1)|浏览(337)

我有这样的错误:

传递给Symfony\Component\HttpFoundation\Request::__construct()的参数1必须是数组类型,给定字符串,在第68行的C:\xampp\htdocs\satusehat2\app\Http\Controllers\PasienController.php中调用。

这是我的职责

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 = '';
sqxo8psd

sqxo8psd1#

您可以改用Symfony\Component\HttpFoundation\Request::create(),它隐式调用请求工厂并返回Request对象。

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

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

相关问题