PHP,异步PUT请求与guzzle库

时间:2018-01-19 11:29:06

标签: php rest asynchronous guzzle

我正在尝试创建异步put请求但是某些东西不起作用,调用没有执行,没有错误,promise返回“{}”。

<script type="text/javascript" charset="utf-8">
    window.addEventListener('load', () => {
      const widgetElement = document.createElement('widget')
      // document.body is not necessary here, it can be any other element
      document.body.appendChild(widgetElement) 

      const widgetCode = document.createElement('script')
      widgetCode.src = '<path to bundled angular app>'
      document.body.appendChild(widgetCode)
    })
</script>

并且有一个电话本身:

protected $guzzle;
function __construct()
{
    $this->guzzle = new \GuzzleHttp\Client(['cookies' => true]);
}

提前感谢您的回答! 干杯!

1 个答案:

答案 0 :(得分:0)

代码看起来很好,你可能想要为它添加更多的错误处理程序。

如果我是你: - &gt;下面(...) - &gt;否则(函数($ error){/ *以某种方式记录错误* /})

还有一些小变化:

  • $response->getBody();$response->getBody()->getContents();(获取字符串,而不是流)
  • 对于基本身份验证,最好使用auth方法的sendAsync()选项