Php post http request using json
<p>Hi I'm trying to send this json object using the POST method but i'm not sure how to include the headers below, i was checking a lot of examples, but no one uses the headers below listed.</p>

<p>This is the code of my php processing page, this page will process the inputs received from a form.html and will create the json object to be transferred to the http server (external platform)    </p>

<pre><code>&lt;?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" =&gt; $msisdn, 
        "mensaje" =&gt; "$mensaje", 
    ); 
    $json_array=json_encode($php_array); 
    echo "Conexion Exitosa, puerto: " . $puerto."\n\n"; 
    echo $json_array; 
    socket_write($socket, $json_array); 
    // Receive the results (if any) from the server 
    $server_response = socket_read($socket, $BUFF); 
    $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); 
?&gt;
</code></pre>

<p>these are the headers information, where i whould include them ? how to do it ? using cURL ? do you have a good example ?</p>

<pre><code>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: */*
</code></pre>

<p>I hope you can help me. The php code above is not working because some of the information (POST, Content-Length, Content-Type, User-Agent...etc ) is not being included (except "host" which did was included).</p>

<p>I managed to did this but it's not working:</p>

<pre><code>&lt;?php
$str_obj_json='{
"method":"SUBMIT","params":{
"batchType":"submit",
"batchId":"alvarons",
"origAddr":"550",
"origTon":2,
"userData":"Movistar les desea Feliz Navidad",
"submits":
 [
  {
  "messId":"mess127_001",
  "destAddr":"51975375377"}
 ]
  }
}';
$ch = curl_init('http://10.10.237.8:21098/SMBULK/BATCH');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $str_obj_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: 395',
'Authorization: Basic dGVzdDp0ZXN0',
'User-Agent: Wget/1.12 (solaris2.10)',
'Connection: Keep-Alive',
'Accept: */*')
);
$result = curl_exec($ch);
?&gt;
</code></pre>

<p>What is wrong ?    </p>
