XML : php socket write xml and keep alive

I'm creating a new itegration with XIQS in php, and they require to open a connection with a socket, then pass a login request with specific xml.

I'm able to create a socket but I cant pass the xml properly as I get 400 error all the time.

the docs: http://vpn.iqsim.com:8080/iqSimWiki/index.php?title=XIQS_Client_/_Server_Communications

my code:

  $xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n".'      <command name="loginXIQS">'."\n".'          <param type="string">USERNAME</param>'."\n".'          <param type="string">PASSWORD</param>'."\n".'      </command>'."\n";    echo "<h2>TCP/IP Connection</h2>\n";    $address = '217.108.104.101';  $service_port = 8000;    /* Create a TCP/IP socket. */  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);  if ($socket === false) {      echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";  }   else {      echo "OK.\n";  }    echo "Attempting to connect to '$address' on port '$service_port'...";  $result = socket_connect($socket, $address, $service_port);  if ($result === false) {      echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";  }   else {      echo "OK.\n";  }    $in = "HEAD / HTTP/1.1\r\n";  $in .= "Content-Type: text/xmlrn";  //$in.= "Host: www.example.com\r\n";  $in.= "Connection: keep-alive\r\n\r\n";  $in.= "rn";  $in.= $xml;    $out = '';    echo "Sending HTTP HEAD request...";  socket_write($socket, $in, strlen($in));  echo "OK.\n";    echo "Reading response:\n\n";  while ($out = socket_read($socket, 2048)) {      echo $out;  }    echo "Closing socket...";  socket_close($socket);  echo "OK.\n\n";    

any ideas how to write xml to socket?

No comments:

Post a Comment