php - Symfony2 : send a HTTP Request -


i trying make http request 1 of controller contact url, goal being contact url, , print html answer in page. tried :

$r = new request(); $r->create('http://www.google.com', 'get');  return $this->render(...mytemplate..., array('name' => $r->getcontent()); 



template printing variable "name".
when that, nothing returned. seems me request never sent, why nothing returned.

my question : how send request , content of response?

thanks in advance.

edit: made gremobuzzbundle buzz browser. it's similar sensiobuzzbundle has nice configuration options.

i suggest use buzz browser , dependency injection. buzz wrapper around curl or file_get_contents. edit deps file adding these lines:

[buzz]     git=https://github.com/kriswallsmith/buzz.git     target=/buzz 

then install vendors download library:

php bin/vendors install 

then add two services (src/yourcompany/yourbundle/resources/config/services.yml):

# curl client buzz buzz.client.curl:   class:  buzz\client\curl   public: false   calls:     - [setverifypeer, [false]]  # buzz browser buzz.browser:   class:     buzz\browser   arguments: ['@buzz.client.curl'] 

the first service client (i prefer curl on file_get_contents), latter browser itself. last step add 1 line of code in autoloader (app/autoload.php):

$loader->registernamespaces(array(     'buzz' => __dir__.'/../vendor/buzz/lib', )); 

then can service , user browser in controller code:

$browser = $this->get('buzz.browser'); $response = $browser->get('http://www.google.com'); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -