HTTP In not accepting Content-Type application/xml

Hi all, Node Red rookie here.

I'm trying to set up a simple workflow to receive a POST in XML format and save it as a file. I can't figure out what I'm doing wrong. I'm using the example workflow "network > http > Post file to a flow".

My problem is with the initial HTTP In node. When I POST a JSON file with or without headers (Content-Type) it works fine. If I post an XML file with no header, it works but it adds root braces like it's encapsulating it in a JSON object, and adding /r characters which is not really what I want. If I POST with "Content-Type: application/xml" it shows as an empty payload. I've also tried "application/octet-stream" and "text/plain" and none of these seem to work either (empty payload).

I've searched and it seems like this should work, so I assume this is something I'm doing wrong. I've also tried sending the POST from different systems (curl, postman) and same issue.

I'm using the latest NodeRed docker version (3.1.10)

Thank you for any help.

Welcome to the forums @silversurfer600

Sometime ago the content type validation routine was relaxed.
I wonder if there are a few ghosts in the system since?

@knolleary - any thought

I see an issue with your payload in the image it seems to be an object. How are you posting the xml in the body of the post. Can wee see your curl or postman.

Posting it to a http in without headers I get.


And exactly the same with application/xml

[edit]
I get your error if i post a json to the in, with xml headers.

what if you use application/xml as the Content-Type

Unless I'm mistaken, its when that Content-Type is set problems occur?

(Note : It's Friday, so you know... Gin O'Clock and all that :grin: )

Moving along.... :pleading_face:

1 Like

works fine here:

flow

[{"id":"69a64e3d.84da3","type":"http in","z":"90e2df527c725ffb","name":"","url":"/hello-xml","method":"post","upload":false,"swaggerDoc":"","x":340,"y":580,"wires":[["43e49c36.dc7624","3a73da553d9a8e9b","0d8765845722da3b"]]},{"id":"43e49c36.dc7624","type":"http response","z":"90e2df527c725ffb","name":"","statusCode":"","headers":{},"x":670,"y":580,"wires":[]},{"id":"8cb4b74e.602c28","type":"comment","z":"90e2df527c725ffb","name":"Post data to a flow","info":"The `HTTP In` node can listen for POST requests.  It returns the posted data as `msg.payload`.\n\nSee Node-RED cookbook items(\n[post raw data(https://cookbook.nodered.org/http/post-raw-data-to-a-flow), [post form data](https://cookbook.nodered.org/http/post-form-data-to-a-flow), [post JSON data](https://cookbook.nodered.org/http/post-json-data-to-a-flow)\n) for details.","x":350,"y":540,"wires":[]},{"id":"ec661b6b.c3c2b8","type":"http request","z":"90e2df527c725ffb","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/hello-xml","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"application/xml","valueValue":""}],"x":550,"y":680,"wires":[["7c2812c.c6ee7ec"]]},{"id":"7c2812c.c6ee7ec","type":"debug","z":"90e2df527c725ffb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":680,"wires":[]},{"id":"e45041b6.9ec13","type":"inject","z":"90e2df527c725ffb","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":275,"y":680,"wires":[["7384647df4a7c001"]],"l":false},{"id":"af33dae7.b21138","type":"comment","z":"90e2df527c725ffb","name":"Send HTTP POST request: http://localhost:1880/hello-raw","info":"","x":470,"y":640,"wires":[]},{"id":"0d8765845722da3b","type":"debug","z":"90e2df527c725ffb","name":"recieved","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":680,"y":520,"wires":[]},{"id":"7384647df4a7c001","type":"template","z":"90e2df527c725ffb","name":"xml data","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<note>\n    <to>Tove</to>\n    <from>Jani</from>\n    <heading>Reminder</heading>\n    <body>Don't forget me this weekend!</body>\n</note>","output":"str","x":380,"y":680,"wires":[["ec661b6b.c3c2b8"]]},{"id":"3a73da553d9a8e9b","type":"xml","z":"90e2df527c725ffb","name":"","property":"payload","attr":"","chr":"","x":550,"y":480,"wires":[["daec8a036df5d385"]]},{"id":"daec8a036df5d385","type":"debug","z":"90e2df527c725ffb","name":"parsed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":480,"wires":[]}]

curl

 curl -i -X POST -H "Content-Type: application/xml" -d "^<?xml version="1.0" encoding="ISO-8859-1"?^>^<note^>    ^<to^>Tove^</to^>    ^<from^>Jani^</from^>    ^<heading^>Reminder^</heading^>    ^<body^>Don't forget me this weekend-i</body^>^</note^>" http://192.168.x.y:1880/hello-xml

Hi thanks for the responses!

I directly copied your curl and send it to my flow and I get an empty payload:

curl -i -X POST -H "Content-Type: application/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend-i</body></note>" http://10.0.xx.xxx:1880/hello-upload

So clearly this is working for everyone but me... maybe I should pull an older version? I've tried pulling a newer container image but same deal.

So I've deleted the container and all data.

pulled "nodered/node-red:latest-14"

Imported "Examples > flows > node-red > network > http > 06 - Post a file to a flow"

Added a Debug

Deploy

Run curl:

curl -i -X POST -H "Content-Type: application/xml" -d "^<?xml version="1.0" encoding="ISO-8859-1"?^>^<note^>    ^<to^>Tove^</to^>    ^<from^>Jani^</from^>    ^<heading^>Reminder^</heading^>    ^<body^>Don't forget me this weekend-i</body^>^</note^>" http://10.0.xx.xxx:1880/hello-upload

And I get msg.payload 'empty'.

Is there more setup that I'm missing? Do I need to be editing 'settings.js' to get this to work?

Uncheck accept file uploads. As the xml is plain text.

See? I knew it was something stupid I was doing.

That was the issue. Thanks all!

1 Like

If you had imported the demo flow that I did for you would have seen it did not have "accept file uploads" enabled :man_shrugging:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.