我尝试使用Guzzle 6(最新版本)以异步方式发布数据
$client = new Client();
$request = $client->postAsync($url, [
'json' => [
'company_name' => 'update Name'
],
]);但是我在终端上没有收到任何类似于post请求的请求
发布于 2019-02-11 14:07:37
因为它是一个promise,,所以你需要把then
并且promise不会调用,除非您将$promise->wait()
根据您的问题,这是一个使用postAsync的简单post请求:
$client = new Client();
$promise = $client->postAsync($url, [
'json' => [
'company_name' => 'update Name'
],
])->then(
function (ResponseInterface $res){
$response = json_decode($res->getBody()->getContents());
return $response;
},
function (RequestException $e) {
$response = [];
$response->data = $e->getMessage();
return $response;
}
);
$response = $promise->wait();
echo json_encode($response);发布于 2015-07-15 14:26:55
您是否已尝试发送请求?
http://guzzle.readthedocs.org/en/latest/index.html?highlight=async
$client = new Client();
$request = new Request('POST', $url, [
"json" => [
'company_name' => 'update Name']
]);
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();发布于 2016-02-16 14:34:35
您最有可能需要调用wait();
$request->wait();
https://stackoverflow.com/questions/31174914
复制相似问题