Can't post XML content with httprequest node

#1

Hi,
I got my nodes running fine but impossible to post the XML content, no answer ... the end point is correctly setup. Nothing happen in a console... like it was never sent!!!

Can someone verify my Format POST function node, please?

[{"id":"936eb5a4.f98cb8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"903d67b9.5a1f98","type":"inject","z":"936eb5a4.f98cb8","name":"GPS+LBS","topic":"","payload":"IWAP01190215A2232.9806N11404.9355E000.1061830323.8706000908000102,226,10,1440,22327#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":141,"y":65,"wires":[["b6906276.a185f"]]},{"id":"1d81483e.87b608","type":"inject","z":"936eb5a4.f98cb8","name":"LBS+WIFI","topic":"","payload":"IWAP01190215V0000.0000N00000.0000E000.1061830323.8706000908000102,226,10,1440,22327,HOTSPOT|D0:60:8C:E2:C0:9E|47&Cioco|58:6D:8F:49:42:4E|81&Cosmin-Land|14:CC:20:8A:18:50|91&Tavi-home|0C:9D:92:4C:14:38|93#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":142.5,"y":122.00000238418579,"wires":[["b6906276.a185f"]]},{"id":"b6906276.a185f","type":"function","z":"936eb5a4.f98cb8","name":"Get flag and other parts","func":"\n// flag = A\n//IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#\n// flag = V\n//IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97# \n\nmsg.elements = msg.payload.replace('#','').split(\",\"); // this gives an array containing the bits\n// elements[0] is the long string starting IWAP01\nmsg.flag = (msg.elements[0].substr(12,1)) // true or false - A or V\n\nreturn msg","outputs":1,"noerr":0,"x":367,"y":64.99999475479126,"wires":[["d0e8b9c8.b34cf8"]]},{"id":"e4ed18a0.13e1c8","type":"function","z":"936eb5a4.f98cb8","name":"Prepare msg type A","func":"//Prepare JS object and fill out fields before conversion to XML\nvar LocationRQ = {\"$\":{\"xmlns\":\"http://skyhookwireless.com/wps/2005\",\"version\":\"2.26\",\"street-address-lookup\":\"full\"},\"authentication\":[{\"$\":{\"version\":\"2.2\"},\"key\":[{\"$\":{\"key\":\"eJwVwcENACAIBLC3w5BAENCneExl3N3YShP-Rii3I1aJaUzbl1NsgLhykiK1Q1x72X0UYwtA\",\"username\":\"35177180700178\"}}]}],\"gps-location\":[],\"gsm-tower\":[]}\n\n\n// flag = A\n//IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#\n\nlet elements = msg.elements; \nLocationRQ.flag = msg.flag; // true or false - A or V\n\n// Get GPS datas\nlet gpsLoc = {};\nlet degreesN = Number(elements[0].substr(13,2));\nlet minutesN = Number(elements[0].substr(15,7));\nlet ns = elements[0].substr(22,1); // N or S\nlet degreesE = Number(elements[0].substr(23,3));\nlet minutesE = Number(elements[0].substr(26,7));\nlet ew = elements[0].substr(33,1); // E or W\ngpsLoc.latitude = degreesN + minutesN/60; // 2232.9806N\nif (ns === \"S\") LocationRQ.latitude = -LocationRQ.latitude;\ngpsLoc.longitude = degreesE + minutesE/60;\nif (ew === \"W\") LocationRQ.longitude = -LocationRQ.longitude; //11404.9355E\ngpsLoc.speed = elements[0].substr(34,5); // 000.1\ngpsLoc.bearing = elements[0].substr(45,6); // 323.87\ngpsLoc.constellation = {};\ngpsLoc.constellation.nsat = elements[0].substr(54,3) \n\nLocationRQ[\"gps-location\"] = [gpsLoc];\n\n\n// Get LBS datas\nlet e;\nlet gsmTower = {};\ngsmTower.mcc = elements[1];\ngsmTower.mnc = elements[2];\ngsmTower.lac = elements[3]; \ngsmTower.ci = elements[4] ;\nLocationRQ[\"gsm-tower\"] = [gsmTower];\n\nLocationRQ.signalStrength = elements[0].substr(51,3); // 060\nLocationRQ.batteryLevel = elements[0].substr(57,3); // 080\n\n\n\nmsg.payload = {LocationRQ: LocationRQ};\nreturn msg;","outputs":1,"noerr":0,"x":357,"y":164.99999475479126,"wires":[["c778272a.437158"]]},{"id":"c778272a.437158","type":"function","z":"936eb5a4.f98cb8","name":"Format msg A","func":"\ndelete msg.payload.LocationRQ.flag;\ndelete msg.payload.LocationRQ.signalStrength;\ndelete msg.payload.LocationRQ.batteryLevel;\n\nreturn msg;","outputs":1,"noerr":0,"x":349,"y":203.00000047683716,"wires":[["7c06d5c8.41d98c","e6f7d5f0.10ad28"]]},{"id":"7b9a6ab0.a2ef84","type":"function","z":"936eb5a4.f98cb8","name":"Prepare msg type V","func":"//Prepare JS object and fill out fields before conversion to XML\n//var LocationRQ = {\"$\":{\"xmlns\":\"http://skyhookwireless.com/wps/2005\",\"version\":\"2.26\",\"street-address-lookup\":\"full\"},\"authentication\":[{\"$\":{\"version\":\"2.2\"},\"key\":[{\"$\":{\"key\":\"eJwVwcENACAIBLC3w5BAENCneExl3N3YShP-Rii3I1aJaUzbl1NsgLhykiK1Q1x72X0UYwtA\",\"username\":\"35177180700178\"}}]}],\"access-point\":[{\"mac\":[\"E01C413B9414\"],\"ssid\":[\"SkyFi-Corp\"],\"signal-strength\":[\"-66\"]},{\"mac\":[\"E01C413BD528\"],\"ssid\":[\"SkyFi-Corp\"],\"signal-strength\":[\"-63\"]},{\"mac\":[\"E01C413BD514\"],\"ssid\":[\"SkyFi-Corp\"],\"signal-strength\":[\"-68\"]}]}\nvar LocationRQ = {\"$\":{\"xmlns\":\"http://skyhookwireless.com/wps/2005\",\"version\":\"2.26\",\"street-address-lookup\":\"full\"},\"authentication\":[{\"$\":{\"version\":\"2.2\"},\"key\":[{\"$\":{\"key\":\"eJwVwcENACAIBLC3w5BAENCneExl3N3YShP-Rii3I1aJaUzbl1NsgLhykiK1Q1x72X0UYwtA\",\"username\":\"35177180700178\"}}]}],\"access-point\":[],\"gsm-tower\":[]}\n\n// flag = V\n//IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97# \n\nlet elements = msg.elements; \nLocationRQ.flag = msg.flag; // true or false - A or V\n\n\n// Get LBS datas\nlet e;\nlet gsmTower = {};\ngsmTower.mcc = elements[1] // 460\ngsmTower.mnc = elements[2] // 0\ngsmTower.lac = elements[3] // 9520 \ngsmTower.ci = elements[4] // 3671\nLocationRQ[\"gsm-tower\"] = [gsmTower];\n\n\n// Get WIFI datas \nlet i;\nlet wifiAccessPointsStrings = elements[5].split(\"&\")\nlet j;\nlet ap = [];\nfor (j = 0; j < wifiAccessPointsStrings.length; j++) {\n let baseElements = wifiAccessPointsStrings[j].split(\"|\")\n ap.push({ ssid: baseElements[0], mac: baseElements[1].replace(/:/g,\"\"), [\"signal-strength\"]: baseElements[2] }) // Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97\n}\n// adjust baseCountwifiAccessPoints just in case the number actually there didn't match that expexted\nLocationRQ.baseCountwifiAccessPoints = ap.length\nLocationRQ[\"access-point\"] = ap;\n\nmsg.payload = {LocationRQ: LocationRQ};\nreturn msg","outputs":1,"noerr":0,"x":357,"y":244.99999475479126,"wires":[["4f30d3e8.564f4c"]]},{"id":"4f30d3e8.564f4c","type":"function","z":"936eb5a4.f98cb8","name":"Format msg V","func":"\ndelete msg.payload.LocationRQ.flag;\ndelete msg.payload.LocationRQ.signalStrength;\ndelete msg.payload.LocationRQ.batteryLevel;\ndelete msg.payload.LocationRQ.baseCountwifiAccessPoints\n\nreturn msg;","outputs":1,"noerr":0,"x":347,"y":290.0000014305115,"wires":[["7c06d5c8.41d98c","e6f7d5f0.10ad28"]]},{"id":"d0e8b9c8.b34cf8","type":"switch","z":"936eb5a4.f98cb8","name":"Route A/V","property":"flag","propertyType":"msg","rules":[{"t":"eq","v":"A","vt":"str"},{"t":"eq","v":"V","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":147,"y":204.99999475479126,"wires":[["e4ed18a0.13e1c8"],["7b9a6ab0.a2ef84"]]},{"id":"7c06d5c8.41d98c","type":"xml","z":"936eb5a4.f98cb8","name":"","property":"payload","attr":"","chr":"","x":587,"y":244.99999475479126,"wires":[["2eb812a5.546efe","53261400.3d2d1c"]]},{"id":"53261400.3d2d1c","type":"function","z":"936eb5a4.f98cb8","name":"Format  POST","func":"// Get positions \n\nmsg.headers = {};\nmsg.headers['content-type'] = 'application/xml';\nreturn msg;\n","outputs":1,"noerr":0,"x":616.0000076293945,"y":297.0000014305115,"wires":[["8b026548.ba6778"]]},{"id":"8b026548.ba6778","type":"http request","z":"936eb5a4.f98cb8","name":"SKYHOOK REQUEST","method":"POST","ret":"txt","url":"https://global.skyhookwireless.com/wps2/location","tls":"","x":633.0000152587891,"y":376.0000057220459,"wires":[["9a0e6a84.bad198"]]},{"id":"9a0e6a84.bad198","type":"debug","z":"936eb5a4.f98cb8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":846.3000106811523,"y":371.80000591278076,"wires":[]},{"id":"e6f7d5f0.10ad28","type":"debug","z":"936eb5a4.f98cb8","name":"Debug JS Obj","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":617,"y":164.99999475479126,"wires":[]},{"id":"2eb812a5.546efe","type":"debug","z":"936eb5a4.f98cb8","name":"Final XML","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":717,"y":244.99999475479126,"wires":[]}]`
0 Likes

#2

It works for me ? Did try restarting your browser and/or node-red ?

0 Likes

#3

Thanks! It was just an error in my httprequest function node...
Wrote : msg.headers['content-type'] = 'application/xml';
as it should be : msg.headers['content-type'] = 'text/xml';

0 Likes