-- . . .
local postData = '{"on":true}\r\n'
local hostIP = "192.168.1.71"
conn:send(table.concat ({
"PUT /api/username/lights/4/state",
"HTTP/1.1","Host: " .. hostIP,
"Connection: close","Accept: text/plain",
"Content-Type: text/plain;charset=UTF-8",
"Content-Length: " .. #postData, '', postData
} ,"\r\n")
-- . . .
Note the extra empty field to generate the double CRLF.