Make a POST with application/x-www-form-urlencoded payload  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Make a POST with application/x-www-form-urlencoded payload

Post by Number8 »

Hello,
I have to send a POST with an application/x-www-form-urlencoded payload. I'm wondering what the syntax should be?
Current script is:

Code: Select all

			
dz.openURL({
        url = url,
	method = "POST",
        callback = "return",
        postData = {
          turn = "toggle"
        }
})
Thank you
Debian buster on NUC and three RPi with buster.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Make a POST with application/x-www-form-urlencoded payload

Post by waaren »

Number8 wrote: Wednesday 28 October 2020 9:31 I have to send a POST with an application/x-www-form-urlencoded payload. I'm wondering what the syntax should be?
Something like this ?

Code: Select all

dz.openURL({
                url = url,
                method = 'POST',
                headers = { ['content-Type'] = 'application/x-www-form-urlencoded' },
                postData = { ['turn'] = 'toggle' },
                callback = 'return',
            })
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Make a POST with application/x-www-form-urlencoded payload

Post by Number8 »

Thanks waaren
Unfortunately it does not work, I don't know why. Strange the API does not return any error.
Using GET however works

Code: Select all

'IPAddress/relay/0?turn=toggle'
Debian buster on NUC and three RPi with buster.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Make a POST with application/x-www-form-urlencoded payload

Post by Number8 »

Using this curl command works

Code: Select all

curl -X POST -d "turn=toggle"  http://IPaddress/relay/0
What would be then dzVents syntax?
Debian buster on NUC and three RPi with buster.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Make a POST with application/x-www-form-urlencoded payload  [Solved]

Post by Number8 »

The correct syntax is

Code: Select all

dz.openURL({
        url = url,
	method = 'POST',
        postData = { turn = 'on' },
        callback = 'return'
	})
Debian buster on NUC and three RPi with buster.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest