我已经在我的应用程序中安装了Guzzle Bundle,并在我打电话时收到了401未经授权的响应。在我的Dev RestClient中有一个Basic Auth的设置,我输入了用户名和密码,它可以工作。但是我无法使用symfony在我的控制器中使用它。我的猜测是config.yml中有一些我不理解的东西。
控制器
/**
* Charting\Backoffice controller.
*/
class BackOfficeController extends Controller
{
/**
* Lists all MTI_Cart\AODHomePage entities.
*
* @Route("/", name="backoffice_index")
* @Method("GET")
*/
public function indexAction()
{
$client = $this->get('guzzle.client.api_backoffice');
$response = $client->get('/users');
var_dump($response); die;
}
}
我的配置
guzzle:
clients:
api_backoffice:
base_url: "http://chartingapi.com"
# custom headers
headers:
Accept: "application/json"
# guzzle client options (full description here: http://guzzle.readthedocs.org/en/latest/request-options.html)
# NOTE: "headers" option is not accepted here as it is provided as described above.
options:
auth:
- backoffice # login
- mysupercoolpassword # password
timeout: 30
# plugin settings
#plugin:
#wsse:
#username: backoffice
#password: mysupercoolpassword
#####in case we want to consume another api
#api_some_otherapi:
# base_url: "http://api.crm.tld"
# headers:
# Accept: "application/json"
P.S ......上面的间距是正确的,只是没有想出如何使这个输入形式表现得像我想要的那样。 (想象一下,向左边的4个空间开枪)
所以要重新说明:当我运行上面配置中列出的用户名和密码时它在POSTMAN中工作正常,但是当使用此配置/ guzzle运行它时,我获得401未经授权