![]() |
|
Help me to send a simple HTTP post - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Help me to send a simple HTTP post (/showthread.php?tid=3467) |
Help me to send a simple HTTP post - pouralise - 12.07.2021 I want to send a HTTP post like this Code: POST /person/takeFacePicture HTTP/1.1
Host: partner.hanet.ai
Content-Length: 48
token=%3CACCESS_TOKEN%3E&deviceID=%3CdeviceID%3Eor via curl Code: curl --location --request POST 'https://partner.hanet.ai/person/takeFacePicture' \
--data-urlencode 'token=<ACCESS_TOKEN>' \
--data-urlencode 'deviceID=<deviceID>'How can I write the code? I'm a novice so I read other similar thread but still dont know how to do. Please help me with this example RE: Help me to send a simple HTTP post - admin - 12.07.2021 Try this, change data inside encodepost table as needed: Code: require('socket.http')
function encodepost(t)
local res = {}
local esc = require('socket.url').escape
for k, v in pairs(t) do
res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
end
return table.concat(res, '&')
end
url = 'https://oauth.hanet.com/token'
payload = encodepost({
code = 'CODE',
grant_type = 'authorization_code',
client_id = 'CLIENT_ID',
redirect_uri = 'HTTP_CALLBACK_URL',
client_secret = 'CLIENT_SECRET',
})
res, err, headers, status = socket.http.request(url, payload)
log(res, err, headers, status)RE: Help me to send a simple HTTP post - pouralise - 12.07.2021 Thank you, it works like a charm. I have another question, can Logic Machine get HTTP post? Like the logicmachine IP is 192.168.1.10 and another device send this to logic machine Code: [code]POST / HTTP/1.1
Host: {{BASE_URL}}
Authorization: Authorization
Content-Length: 283
{
"action_type": "update",
"data_type": "place",
"date": "2020-12-11 11:14:40",
"hash": "e4a296a0a9d3f958b4262d9680db4bee",
"id": "de73e412-7baf-4237-9b09-7470eddd4996",
"keycode": "",
"placeID": "108",
"placeName": "Team dev",
"time": 1607660080000
}Can Logic machine receive it and get the data like "placeID" = "108"? |