【问题标题】:Argument 1 passed to GuzzleHttp\Client::send() must implement interface传递给 GuzzleHttp\Client::send() 的参数 1 必须实现接口
【发布时间】:2021-12-17 13:27:34
【问题描述】:

嗨,我是 laravel 新手,我正在尝试使用 laravel 8 使用 api 我的 POST 有问题,我不明白

public function storeEntreprise(Request $request){
        $request->validate([
            'name' => 'required',
            'email' => 'required',
            'phone_number'=>'required',
            'address' => 'required',
            'password' => 'required',
            'password_confirmation' => 'required'
        ]);

        $client = new Client();

        $post = $request->all();

        $url = "http://flexy-job.adsyst-solutions.com/api/entreprises-store";
        $create = $client->request('POST', $url, [
            'headers' => [
                'Content-Type' => 'text/html; charset=UTF8',
            ],
            'form-data' => [
               'name'           => $post['name'],
               'email'        => $post['email'],
               'phone_number'          => $post['phone_number'],
               'address'          => $post['address'],
               'logo'        => $post['logo'],
               'password'       => $post['password'],
               'password_confirmation'      => $post['password_confirmation']
           ]
        ]);
        //dd($create->getBody());
        echo $create->getStatusCode();
        //echo $create->getHeader('Content-Type');
        echo $create->getBody();
        $response = $client->send($create);
        return redirect()->back();

    }

你能帮帮我吗

【问题讨论】:

    标签: httpclient laravel-8 guzzle


    【解决方案1】:

    您调用(不小心?)$response = $client->send($create);,其中$create 是您发出的 API 请求的响应 ($create = $client->request('POST', $url, ...)。

    所以PHP 报告你不能通过ResponseInterface 哪里需要RequestInterface

    另外,你echo的响应体,同时返回重定向响应。因此浏览器不会向您显示 API 响应(因为实例返回重定向)。

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 2015-11-18
      • 2021-10-19
      • 1970-01-01
      • 2013-10-03
      相关资源
      最近更新 更多