Skip to content

Instantly share code, notes, and snippets.

@AlexR1712
Created July 27, 2016 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexR1712/45456c238c4ad2b81e3a62861847fc64 to your computer and use it in GitHub Desktop.
Save AlexR1712/45456c238c4ad2b81e3a62861847fc64 to your computer and use it in GitHub Desktop.
cURL POST
<?php
$ch = curl_init();
$fields =
http_build_query(
[
'dato1' => 2016,
'dato2' => 2017
]
);
curl_setopt($ch, CURLOPT_URL,"http://httpbin.org/post");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// Recibiendo respuesta
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Ejecutar cURL
$server_output = curl_exec ($ch);
// Cerrar conexion cURL
curl_close ($ch);
// Procesar respuesta
if ($server_output == "OK") {
var_dump($server_output);
}
else
{
echo('Error: <br>');
var_dump($server_output);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment