I am trying to make a HTTP Request from one of my controller to contact another URL, the goal being to contact another URL, and to simply print the HTML answer in my page.
I tried :
$r = new Request();
$r->create('http://www.google.com', 'GET');
return $this->render(...mytemplate..., array('name' => $r->getContent());
My template is simply printing the variable “name”.
Now when I do that, nothing is returned. It seems to me that the request is never sent, which is why nothing is returned.
My question is : how do I send the request and get the content of the response?
Thanks in advance.
EDIT: I made a GremoBuzzBundle for Buzz browser. It’s similar to SensioBuzzBundle but it has some nice configuration options.
I would suggest to use Buzz browser and dependency injection. Buzz is a wrapper around cURL or file_get_contents. Edit your
depsfile adding these lines:Then install vendors to actually download the library:
Then add two services (
src/YourCompany/YourBundle/Resources/config/services.yml):The first service is the client (i prefer cURL over file_get_contents), the latter is the browser itself. The last step is to add one line of code in the autoloader (
app/autoload.php):Then you can get the service and user the browser in your controller code: