public function httpTest() { $url = "自己可以写一个模拟地址,例如下面的 httpTest2 先让他挂起一定的时间,timeout设置超时时间,如果超过timeout的时间 会自动抛出异常,去发短信等..."; $client = new Client(); try { $response = $client->request('POST', $url, [ 'headers' => ['Content-Type' => 'application/json'], 'json' => [1,2,3,4,5,6], 'timeout' => 5 // "debug"=>true ]); $body = $response->getBody()->getContents(); var_dump('$body'); var_dump($body); } catch(\Throwable $e) { # 在这里干一些你需要干的事情,例如发送短信预警,发送邮件等等 var_dump('--------------1-----------------'); $errorCode= $e->getCode(); $errorMessage = $e->getMessage(); return json(['code'=>$errorCode,'msg'=>$errorMessage]); } } public function httpTest2() { $params = Request::post(); var_dump($params); sleep(5); return json(['status'=>200]); }
标签:body,dump,后处理,json,timeout,var,超时,GuzzleHttp From: https://www.cnblogs.com/G921123/p/17814845.html