This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Help me to send a simple HTTP post
#1
I want to send a HTTP post like this

Code:
12345
POST /person/takeFacePicture HTTP/1.1 Host: partner.hanet.ai Content-Length: 48 token=%3CACCESS_TOKEN%3E&deviceID=%3CdeviceID%3E

or via curl

Code:
123
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
Reply
#2
Try this, change data inside encodepost table as needed:
Code:
12345678910111213141516171819202122232425
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)
Reply
#3
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:
1234567891011121314151617
[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"?
Reply


Forum Jump: