如何返回验证来自api

时间:2019-07-26 17:41:40

标签: php laravel-5 guzzle

**Need to return laravel validation response which is come from Post API

使用Laravel 5.2从表单中进行请求**

控制器代码:-

public function aperi(Request $request){ 
        $endpoint = "MyURL";
        $client = new \GuzzleHttp\Client();
        $name = $request->addavpname;
        $email = $request->addavpemail;
        $status = $request->addStatus;

        $response = $client->request('POST', $endpoint, ['query' => [
            'addavpname' => $name, 
            'addavpemail' => $email,
            'addStatus' => $status
        ]]);


        $statusCode = $response->getStatusCode();
        $content = $response->getBody();

    $content = json_decode($response->getBody(), true);

}

来自服务器的响应:-

  Client error: `POST "MY URL" 
  addavpname=No%20avp&addavpemail=noavp%40mobilelinkusa.com&addStatus=active` 
  resulted in a `400 Bad Request` response:
   {"addavpname":["The addavpname has already been taken."],"addavpemail": 
    ["The addavpemail has already been taken."]}

请帮助我。 如何解决?谢谢

0 个答案:

没有答案