从 Symfony2 中受凭据保护的 URL 检索数据的最佳方法是什么?

What is the best way to retrieve data from a URL protected by credentials in Symfony2?

我可以从 Symfony2 项目中受凭据保护的路由检索数据 (JSON),但为此我使用 file_get_contents($url, $include_path, $context)stream_context_create($options)。没有上下文,它无法打开流。

执行此类操作的最佳方法是什么?有一些简单的 Symfony 的 API ?

我也提供使用 Guzzle for this operation. You can check Guzzle Stream 页面。