Estoy intentando enviar un mensaje JSON a un servidor HTTP externo en php usando el metodo POST, nunca he hecho peticiones HTTP, sin embargo he llegado hasta este punto:
--Como aprecian envío el mensaje JSON ya codificado:
Código PHP:
<?php
$host ="10.10.237.8";
$puerto = 21098;
$BUFF = 2048;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$conexion = socket_connect($socket, $host, $puerto);
if($conexion)
{
$msisdn=$_POST["msisdn"];
$mensaje=$_POST["mensaje"];
$php_array = array(
"numero" => $msisdn,
"mensaje" => "$mensaje",
);
$json_array=json_encode($php_array);
echo "Conexion Exitosa, puerto: " . $puerto."\n\n";
echo $json_array;
socket_write($socket, $json_array);
$server_response = socket_read($socket, $BUFF); // Receive the results (if any) from the server
$decoded_response = json_decode($server_response, true); // decode the data received
echo $decoded_response['passphrase']; // and spit the results
}
else
{
echo "\nLa conexion TCP no se pudo realizar, puerto: ".$puerto;
}
socket_close($socket);
?>
Código HTML:
POST /SMBULK/BATCH HTTP/1.0 Authorization: Basic dGVzdDp0ZXN0 Host: 10.10.237.8:21098 Content-Length: 395 User-Agent: Wget/1.12 (solaris2.10) Content-Type: application/x-www-form-urlencoded Connection: Keep-Alive Accept: */*
- Donde debo incluir dicha información requerida por el servidor http ?