参数 1 传递给 Symfony\Component\HttpFoundation\Request::__construct()
P粉378890106
P粉378890106 2024-02-26 11:29:01
0
1
240

我有这样的错误:

传递给 Symfony\Component\HttpFoundation\Request::__construct() 的参数 1 必须是给定的数组、字符串类型,在 C:\xampp\htdocs\satusehat2\app\Http\Controllers\PasienController 中调用.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 = '';

P粉378890106
P粉378890106

全部回复(1)
P粉124070451

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

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

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!