我正在尝试发出异步放置请求,但有些东西不起作用,调用没有执行,没有错误,promise 返回"{}"。
protected $guzzle;
function __construct()
{
$this->guzzle = new GuzzleHttpClient(['cookies' => true]);
}
还有一个电话本身:
$request = new GuzzleHttpPsr7Request('PUT', $call->callback_url,
[
'cache-control' => 'no-cache',
'Authorization' => 'Basic ' . $hash,
'content-type' => 'application/x-www-form-urlencoded',
'paymentStatusId' => "$orderstatusID"
]);
$promise = $this->guzzle->sendAsync($request)->then(
function (PsrHttpMessageResponseInterface $response) use ($call) {
if ($response->getBody() == '1') {
$call->shopware_response = $response->getBody();
$call->status = 'success';
} else {
$call->status = 'to_renewal';
}
$call->save();
}
);
$promise->wait();
提前感谢您的回答!干杯!
代码看起来不错,您可能希望向其添加更多错误处理程序。
如果我是你:->然后(...->否则(函数 ($error( {/* 以某种方式记录错误 */}(
还有一些小的变化:
-
$response->getBody();
到$response->getBody()->getContents();
(获取字符串,而不是流( - 对于基本身份验证,最好使用
auth
sendAsync()
方法的选项