Parameter 1 passed to Symfony\Component\HttpFoundation\Request::__construct()
P粉378890106
P粉378890106 2024-02-26 11:29:01
0
1
238

I have this error:

Parameter 1 passed to Symfony\Component\HttpFoundation\Request::__construct() must be the given array or string type, in C:\xampp\htdocs\satusehat2\app\Http\Controllers\ PasienController calls .php 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();
        
    }

Line 68 is

$body = '';

P粉378890106
P粉378890106

reply all(1)
P粉124070451

You can use Symfony\Component\HttpFoundation\Request::create() instead, which implicitly calls the request factory and returns a Request object.

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

PS: There is no need to explicitly specify the method parameter, because 'GET' is the default value.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!