php – how w fsockopen soap in express js-ThrowExceptions

Exception or error:

I have this code for call data from public IP fingerprint and commkey number, and that is works in php, my code look like this,

public function getdata(){
$IP= "";
$Key= "";
$Connect = fsockopen($IP, "80", $errno, $errstr, 1);
        $soap_request="<GetAttLog><ArgComKey xsi:type=\"xsd:integer\">".$Key."</ArgComKey><Arg><PIN xsi:type=\"xsd:integer\">All</PIN></Arg></GetAttLog>";
        fputs($Connect, "POST /iWsService HTTP/1.0".$newLine);
        fputs($Connect, "Content-Type: text/xml".$newLine);
        fputs($Connect, "Content-Length: ".strlen($soap_request).$newLine.$newLine);
        fputs($Connect, $soap_request.$newLine);
        while($Response=fgets($Connect, 1024)){
            // var_dump($buffer);
        $buffer = Parse_Data($buffer,"<GetAttLogResponse>","</GetAttLogResponse>");
        $buffer = explode("\r\n",$buffer);
        $result = []; 
            $data = Parse_Data($buffer[$a],"<Row>","</Row>");
            $PIN = Parse_Data($data,"<PIN>","</PIN>");
            $DateTime = Parse_Data($data,"<DateTime>","</DateTime>");
            $Verified = Parse_Data($data,"<Verified>","</Verified>");
            $Status = Parse_Data($data,"<Status>","</Status>");
            $ins = array(
                    "pin"       =>  $PIN,
                    "date_time" =>  $DateTime,
                    "ver"       =>  $Verified,
                    "status"    =>  $Status
            $result[$a] = $ins;
        return $result;

and this is the result when i’m var_dump($buffer) in while:
enter image description here

I wanna change code from php to nodejs with expressjs framework, anybody know how to change that code to javascript?

I tried with this code:

 var net = require('net');

 var socket = new net.Socket();
  socket.on('connect', function() {
  console.log('server now connect')
 socket.on('data', function(data) {
  console.log('data from server:' + data);

 socket.connect(PORT, 'IP');

but, stuck and dunno what to do, anybody caould help? thank you

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *