【发布时间】:2017-08-24 02:10:21
【问题描述】:
我是使用 Guzzle 包的新手,我想通过 web api 发送数据,当响应状态为 OK 或 NOT 时,我会执行一些操作,否则状态等于等待我在 5 秒后再次请求或状态等于尚未休眠 30 秒。 这是我的代码
$client = new Client();
$headers= [
'Accept' => 'application/x-www-form-urlencoded',
'Content-Type' => 'application/x-www-form-urlencoded',
];
$body = [
'phone2'=>'723457481',
'amount'=>'200'
];
$url = "http://192.168.31.51:8080/requesttrafic/";
$response = $client->Request("POST", $url, [
'handler' => $stack,
'headers'=>$headers,
'form_params'=>$body
]);
$contents = (string) $response->getBody();
// this $contents can be status 'ok','not' anything
那么如何根据响应状态再次发送? 谢谢
【问题讨论】:
-
我已经编辑了我的答案,也许这就是你要找的。span>
-
那么完美,如果您的问题已经解决,请在stackoverflow上标记已接受的答案以关闭此线程