What alternatives to cURL are there to make requests to an API in php?

1

Would anyone know a function similar to cURL to make requests to an API in php?

So far I have used cURL to make http requests, but I was asked to investigate alternatives, for example in cases where you work in an environment that does not allow modules to be installed, and cUrl is not available, or maybe there is a way lighter and less complex to make simple requests.

Thanks

    
asked by virumi 20.02.2017 в 22:18
source

3 answers

2

You can use this library

link

Example of the same site

$headers = array('Accept' => 'application/json');
$data = array('name' => 'ahmad', 'company' => 'mashape');

$body = Unirest\Request\Body::json($data);

$response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);

Greetings,

    
answered by 20.02.2017 в 22:26
1

You can use file_get_contents() but it would only be used to make the requests by GET .

    
answered by 20.02.2017 в 22:24
0

Alternatively, the extension pecl_http .

$url = 'http://api.sitioconservicios.com/servicios/cualquierwebservicio/';

$respuesta = http_post_data($url, $por_ejemplo_xml);
    
answered by 21.02.2017 в 01:43