如何发布狂饮6异步数据

问题描述 投票:5回答:3

我试图用后的数据作为异步狂饮6(最新版)

    $client = new Client();
    $request = $client->postAsync($url, [
        'json' => [
                'company_name' => 'update Name'
        ],
    ]);

但我没有得到任何申请表狂饮像接线柱要求

php yii2 guzzle
3个回答
4
投票

您是否尝试发送请求?

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();

1
投票

最有可能你需要调用wait();

$request->wait();


1
投票

因为它是一个promise,你需要把then

并承诺不会叫,除非你把$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);
© www.soinside.com 2019 - 2024. All rights reserved.