HTML tag in HTTP request

Hello,

I'm using an HTTP request node to POST something from NR towards a NChat chatbox (SMF forum) which can contain HTML tags, such as:

index.php?message=This is <b>my</b> message. But it gets encoded into "This is &lt;b&gt;my&lt;/b&gt; message"

Can't figure out how to work around this. Any suggestions?

I've wrapped your example as a code block to ensure the raw html gets displayed.

If you're using the URL field of the request node to inset msg.payload, you should use triple braces to prevent the html escaping: {{{ like this }}}.

Sorry, thanks for wrapping up.

I'm using a function node to build the URL :

msg = {
method: 'POST',
url: 'index.php',
headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'User-Agent': 'Mozilla/5.0',
},
payload: {nchat: 'write', p2kflex: myText },
};
return msg;

When changing p2kflex: myText into {{{ p2kflex: myText }}} NR tells me

SyntaxError: Unexpected token '{'

Right, because that isn't valid JavaScript. As I said, the suggestion was based on the assumption you were using the URL field of the request node which supports the mustache syntax for inserting message properties.

Given that isn't the issue here, I'm not immediately sure what the fix is. Does the api docs say anything about how to submit html content?

Hi, I'm pretty new to node-red and wanted ask that how to GET data from http request node for using it for further calculations. And I have also used json parser for this but it is giving error. so, I have tried to minimize the data as much as i can. But, I just want the value = 2 out of the string/ Input tag for calculation. so I'm sharing these images of URL page, flow and the output with you guys. so that i can get the output i want.

image

image

image

[{"id":"f2caf78e.345a68","type":"function","z":"df55e200.6d814","name":"Machine 001","func":"var rowid = { payload: msg.payload[1] };\nreturn rowid;\n\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":870,"y":200,"wires":[["ff907b26.328be8"]]},{"id":"4c1c89ec.ea9f58","type":"inject","z":"df55e200.6d814","name":"","props":[{"p":"payload"},{"p":"topic","v":"topic","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"payload","payloadType":"msg","x":110,"y":200,"wires":[["f29a4bef.affe88"]]},{"id":"6220f2d8.c1e9dc","type":"debug","z":"df55e200.6d814","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":280,"wires":[]},{"id":"f29a4bef.affe88","type":"http request","z":"df55e200.6d814","name":"Product Machine Mapping","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://oee.envirocom.in:1880/home/initial-setup/product-machine-mapping","tls":"","persist":false,"proxy":"","authType":"","x":310,"y":200,"wires":[["888a4798.6e7f08"]]},{"id":"94446714.6c1078","type":"split","z":"df55e200.6d814","name":"","splt":"5","spltType":"len","arraySplt":"5","arraySpltType":"len","stream":true,"addname":"payload","x":690,"y":200,"wires":[["f2caf78e.345a68"]]},{"id":"888a4798.6e7f08","type":"html","z":"df55e200.6d814","name":"","property":"payload","outproperty":"payload","tag":"tr","ret":"html","as":"single","x":530,"y":200,"wires":[["94446714.6c1078"]]},{"id":"ff907b26.328be8","type":"html","z":"df55e200.6d814","name":"","property":"payload","outproperty":"payload","tag":"td","ret":"html","as":"single","x":450,"y":280,"wires":[["a65df3eb.d8e1d"]]},{"id":"a65df3eb.d8e1d","type":"function","z":"df55e200.6d814","name":"pieceValue","func":"var pieceValue = { payload: msg.payload[2] };\nreturn pieceValue;\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":280,"wires":[["b885a827.125ac8"]]},{"id":"b885a827.125ac8","type":"change","z":"df55e200.6d814","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"\"2\"","fromt":"str","to":"2","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"\"piecespercycle\"","fromt":"str","to":"piecespercycle","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\"text\"","fromt":"str","to":"text","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":280,"wires":[["6220f2d8.c1e9dc"]]}]```

The info you want is in a input tag try tr > td > input
set to output an object of any attributes.
e.g.

[{"id":"f29a4bef.affe88","type":"http request","z":"c74669a0.6a34f8","name":"Product Machine Mapping","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://oee.envirocom.in:1880/home/initial-setup/product-machine-mapping","tls":"","persist":false,"proxy":"","authType":"","x":250,"y":4080,"wires":[["888a4798.6e7f08"]]},{"id":"4c1c89ec.ea9f58","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","v":"topic","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"payload","payloadType":"msg","x":250,"y":4140,"wires":[["f29a4bef.affe88"]]},{"id":"888a4798.6e7f08","type":"html","z":"c74669a0.6a34f8","name":"","property":"payload","outproperty":"payload","tag":"tr >  td > input","ret":"attr","as":"single","x":510,"y":4080,"wires":[["db46be19.e35ce"]]},{"id":"db46be19.e35ce","type":"split","z":"c74669a0.6a34f8","name":"","splt":"\\n","spltType":"str","arraySplt":"8","arraySpltType":"len","stream":false,"addname":"","x":570,"y":4140,"wires":[["6220f2d8.c1e9dc"]]},{"id":"6220f2d8.c1e9dc","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":4200,"wires":[]}]

you can then split the array at a length of 8 and each payload will contain a row.
All the info i used to get this I read here

1 Like

Hello @Hunter ,

Did you try to encode the URI with the corresponding javascript function?

https://www.w3schools.com/jsref/jsref_encodeURI.asp

Cheers
Ranki

1 Like

Thank you so much, you solved my one of the major problems Thank you again.

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