Symfony2 : send a HTTP Request

后端 未结 6 714
旧巷少年郎
旧巷少年郎 2021-01-31 21:57

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 tri

6条回答
  •  一生所求
    2021-01-31 22:44

    Two problems.

    First of all, that's not the proper usage of Symfony\Component\HttpFoundation\Request::create(), which is a static initializer/factory of sorts. Your code should look like this

    $r = Request::create( 'http://www.google.com', 'GET' );
    

    Now you have a proper Request object. However, this is irrelevant which is your second problem: that's not how Symfony's request object is designed to work. Its purpose is not for executing HTTP requests, its for representing them as objects in the framework.

    Long story short, you can't do it that way. Perhaps you can use cURL to scrape the page you want?

提交回复
热议问题