在laravel 5.0中guzzle 5.0 postAsync错误

时间:2016-03-25 13:06:43

标签: laravel-5 guzzle

您好我正在尝试在我的laravel应用程序中使用Guzzle将一些数据发送到远程应用程序。当我尝试使用$ client-> post(' url')时,它工作正常,但每当我使用任何异步函数(如postAsync)时,sendAsync都会收到BadMethodException。

local.ERROR: exception 'BadMethodCallException' with message 'Unknown         method, sendAsync' in /home/lycan/Documents/workspace/my_project/vendor/guzzlehttp/guzzle/src/functions.php:324

我的方法如下

private function sendDataToRemoteApplication()
{
    $client = new \GuzzleHttp\Client();
    $url='http://localhost:9000/submitResults/?key1=valu1&key2=22';

    $request = new Request('POST', $url);

    $promise = $client->sendAsync($request)->then(function ($response) {
        echo 'I completed! ' . $response->getBody();
    });
    $promise->wait();

}

我跟踪了文件中的所有内容,所以它应该可以工作! 试图在谷歌找到解决方案,但没有找到任何人面临这个问题的链接....(如果我是第一个面对这个问题,我会认为我自己很幸运:D)。请问一个问题是什么。

1 个答案:

答案 0 :(得分:0)

您可以尝试此操作(\GuzzleHttp\Psr7\Request):

$request = new \GuzzleHttp\Psr7\Request('GET', 'http://example.com');
$promise = $client->sendAsync($request)->then(function ($response) {
    echo 'I completed! ' . $response->getBody();
});
$promise->wait();