Heim  >  Fragen und Antworten  >  Hauptteil

Parameter 1 wird an Symfony\Component\HttpFoundation\Request::__construct() übergeben

Ich habe diesen Fehler:

Parameter 1, der an SymfonyComponentHttpFoundationRequest::__construct() übergeben wird, muss das angegebene Array, String-Typ, sein, das in C:xampphtdocssatusehat2appHttpControllersPasienController.php Zeile 68 aufgerufen wird.

Das ist meine Funktion

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();
        
    }

Linie 68 ist

$body = '';

P粉378890106P粉378890106210 Tage vor235

Antworte allen(1)Ich werde antworten

  • P粉124070451

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

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

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

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

    Antwort
    0
  • StornierenAntwort