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.

curl to lua
#1
Hi,

I am trying to convert a curl command to lua but cannot get it to work...
This is the curl command:

Code:
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0", "id":1", "method": "Input.Down"}' \
http://user:passwd@192.168.0.24:8080/jsonrpc
Result:
Code:
{"id":"1", "jsonrpc":"2.0", "result":"OK"}

This is the lua code:

Code:
socket = require('socket.http')

socket.TIMEOUT = 5
url = 'http://user:passwd@192.168.0.24:8080/jsonrpc'
body = '{"jsonrpc": "2.0", "id": 1, "method": "Input.Down"}'

res, code = socket.request({
    url = url,
    method = 'POST',
    body = body,
    headers = {'Content-Type: application/json'
        }
})                       
log(res)
log(code)
This results in:
Code:
testing 22.01.2022 16:14:46
* number: 200
testing 22.01.2022 16:14:46
* number: 1

Any hints?
TIA.
Reply


Messages In This Thread
curl to lua - by baggins - 22.01.2022, 15:52
RE: curl to lua - by Erwin van der Zwart - 22.01.2022, 22:58
RE: curl to lua - by baggins - 22.01.2022, 23:07
RE: curl to lua - by admin - 24.01.2022, 07:08
RE: curl to lua - by baggins - 24.01.2022, 08:58

Forum Jump: