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.

JSON post request being weird
#3
(21.09.2023, 05:06)admin Wrote: You are missing the content-length header. It is also advisable to use json.encode to create JSON strings instead of manual creation which can lead to errors.

I've added the header, with it in I get a internal server error Sad 

This should be correct, right?
Code:
mac = io.readfile('/sys/class/net/eth0/address'):trim()
require('socket.http')
require('json')
require("ltn12")
jsoncontent = json.encode({fault = true,instID= "teststring",value= 22,name = "stringname"})

body = jsoncontent
response = {}
log("test")

socket.http.request({
      url = "http://192.168.1.69/docs",
   method = 'POST',
     sink = ltn12.sink.table(response),
  headers = {
     ["Content-Length"] = string.len(body),
        ['accept'] = 'application/json',
     ['content-type'] = 'application/json',
            },
      source = ltn12.source.string(body),
        })
log(response,body)
Reply


Messages In This Thread
JSON post request being weird - by Seijboldt - 20.09.2023, 17:16
RE: JSON post request being weird - by admin - 21.09.2023, 05:06
RE: JSON post request being weird - by Seijboldt - 21.09.2023, 05:49
RE: JSON post request being weird - by admin - 21.09.2023, 08:28

Forum Jump: