明天在应用Guzzle时遇到了几个问题,在这里记录一下。

1.报错HttpFoundationFactory not found

Class 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found

遇到这个问题是因为Guzzle的应用是须要依赖这个包的,然而咱们没有,解决办法十分间接:

composer require symfony/psr-http-message-bridge

如果之前没有应用镜像,那么问题就间接解决了,然而如果应用过镜像那就呈现了第二个问题

2.增加依赖包时报错Could not find package

[InvalidArgumentException]  Could not find package symfony/psr-http-message-br  idge.  Did you mean one of these?      symfony/psr-http-message-bridge      loophp/unaltered-psr-http-message-bridge-bundl  e

呈现这个问题的起因是因为应用镜像,解决办法十分间接:

composer config -g --unset repos.packagist


    • -

上面记录一下guzzle的根本用法:

//新建client配置base_uri,能够间接在这前面拼接比拟不便$client = new Client([ 'base_uri' => 'http://127.0.0.1:8000/', 'timeout' => 2.0]);try { return $client->request('GET', '/api/v4/alarms', [ 'auth' => ['admin', 'public'] ]);} catch (GuzzleException $e) { return array([ 'msg' => 'error' ]);}