Created
July 27, 2016 06:00
-
-
Save AlexR1712/45456c238c4ad2b81e3a62861847fc64 to your computer and use it in GitHub Desktop.
cURL POST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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