search

Home  >  Q&A  >  body text

Parameter 1 passed to Symfony\Component\HttpFoundation\Request::__construct()

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粉378890106P粉378890106261 days ago289

reply all(1)I'll reply

  • P粉124070451

    P粉1240704512024-02-27 10:02:10

    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.

    reply
    0
  • Cancelreply