Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipsmartins/d1f71179a68ae50fb8eb872912fab48b to your computer and use it in GitHub Desktop.
Save felipsmartins/d1f71179a68ae50fb8eb872912fab48b to your computer and use it in GitHub Desktop.
POSXML exmple POST raw json + http headers from terminal POS
<stringvariable value="" variable="sBuffer" />
<stringvariable value="POST " variable="sVerb" />
<!-- Path -->
<stringvariable value=' /ping ' variable="sPath" />
<!-- Data to be sent -->
<stringvariable value='{"times": "3", "foo":"3698"}' variable="sPayload" />
<!-- Headers, comma separated: header1:value1,header2:value2 -->
<stringvariable value="Accept:application/json,Content-type:application/json" variable="sHeaders" />
<!-- Concatenate the strings in this order: Method (sVerb), Headers (sHeaders), Path (sPath), Payload (sPayload) -->
<joinstring firstvalue="$(sVerb)" secondvalue="$(sHeaders)" variabledestination="$(sBuffer)" />
<joinstring firstvalue="$(sBuffer)" secondvalue="$(sPath)" variabledestination="$(sBuffer)" />
<joinstring firstvalue="$(sBuffer)" secondvalue="$(sPayload)" variabledestination="$(sBuffer)" />
<!-- Convert the buffer to hexadecimal -->
<integervariable value="0" variable="iSize" />
<string.tohex string="$(sBuffer)" variablereturn="$(sBuffer)" />
<string.length value="$(sBuffer)" variablereturn="$(iSize)" />
<!-- Send the hexadecimal buffer to the host with the command network.send -->
<integervariable value="0" variable="iRet" />
<integervariable variable="iConnect" value=""/>
<!--DEBUG START-->
<cleandisplay />
<display line="1" column="0" message="connecting to Cloudwalk..." />
<!--DEBUG END-->
<!-- Connect to the CloudWalk Walk Server -->
<preconnect variablestatus="$(iConnect)" />
<network.send buffer="$(sBuffer)" size="$(iSize)" variablereturn="$(iRet)" />
<!-- Receive the size of the answer (4 bytes) from the host with the command network.receive -->
<stringvariable value="" variable="sBufferReceive" />
<integervariable value="0" variable="iBytesReceive" />
<network.receive variablebuffer="$(sBufferReceive)" maxsize="4" variablereceivedbytes="$(iBytesReceive)" variablereturn="$(iRet)" />
<!-- Validate if it was possible to receive the size of the answer from the host -->
<if variable="$(iRet)" operator="notequalto" value="1">
<cleandisplay />
<display line="1" column="0" message="ERROR: Unable to send the message" />
<waitkeytimeout seconds="5" />
<network.hostdisconnect />
<exit />
</if>
<!-- Receive the complete answer from the host with the command network.receive -->
<string.fromhex string="$(sBufferReceive)" variablereturn="$(sBufferReceive)" />
<convert.toint base="16" number="$(sBufferReceive)" variablereturn="$(iSize)" />
<network.receive variablebuffer="$(sBufferReceive)" maxsize="$(iSize)" variablereceivedbytes="$(iBytesReceive)" variablereturn="$(iRet)" />
<!-- Validate if it was possible to receive the complete answer from the host -->
<if variable="$(iRet)" operator="notequalto" value="1">
<cleandisplay />
<display line="1" column="0" message="ERROR: unable to receive response" />
<waitkeytimeout seconds="5" />
<network.hostdisconnect />
<exit />
</if>
<!-- Convert the hexadecimal answer and display it -->
<string.fromhex string="$(sBufferReceive)" variablereturn="$(sBufferReceive)" />
<cleandisplay />
<display line="1" column="3" message=" RECEIVED: " />
<display line="2" column="0" message="$(sBufferReceive)" />
<waitkeytimeout seconds="5" />
<network.hostdisconnect />
<waitkey />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment