<?php
//--- GET
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://url-de-la-api/test?param1=value');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
?>
<?php
//--- POST
$fields = array('field1' => 'valor1', 'field2' => urlencode('valor 2'));
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://url-de-la-web/test");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string );
$data = curl_exec($ch);
curl_close($ch);
?>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter