【问题标题】:using Guzzle to get request in async mode使用 Guzzle 在异步模式下获取请求
【发布时间】:2017-10-02 21:29:31
【问题描述】:

我有以下代码:

public function postGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://myexample.com/api/posts";
    $myBody['name'] = "Demo";
    $request = $client->post($url,  ['body'=>$myBody]);
    $response = $request->send();
    dd($response);
}

现在我正在尝试在异步模式下使用它

【问题讨论】:

  • 您的问题到底是什么?说得具体一点。

标签: php laravel guzzle


【解决方案1】:

直接取自文档: http://docs.guzzlephp.org/en/stable/quickstart.html

$promise = $client->getAsync('http://httpbin.org/get');
$promise = $client->deleteAsync('http://httpbin.org/delete');
$promise = $client->headAsync('http://httpbin.org/get');
$promise = $client->optionsAsync('http://httpbin.org/get');
$promise = $client->patchAsync('http://httpbin.org/patch');
$promise = $client->postAsync('http://httpbin.org/post');
$promise = $client->putAsync('http://httpbin.org/put');

【讨论】:

    猜你喜欢
    • 2020-03-22
    • 2015-11-26
    • 2016-10-06
    • 2022-11-28
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多