Symfony2 : send a HTTP Request

后端 未结 6 711
旧巷少年郎
旧巷少年郎 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:21

    https://github.com/CircleOfNice/CiRestClientBundle

    Nice API for easy usage of the curl library and it returns a symfony response instead of a string result

    $restClient = $this->container->get('ci.restclient');
    
    $restClient->get('http://www.someUrl.com');
    $restClient->post('http://www.someUrl.com', 'somePayload');
    $restClient->put('http://www.someUrl.com', 'somePayload');
    $restClient->delete('http://www.someUrl.com');
    $restClient->patch('http://www.someUrl.com', 'somePayload');
    
    $restClient->head('http://www.someUrl.com');
    $restClient->options('http://www.someUrl.com', 'somePayload');
    $restClient->trace('http://www.someUrl.com');
    $restClient->connect('http://www.someUrl.com');
    

提交回复
热议问题