help needed for LG TV IP interface

I’m trying to send command to my LG TV over HTTP, from my Vera.
It works when I send the commands using Chrome REST Console.
But I get “HTTP/1.1 401 Unauthorized” error when I use the code below to send the same command.

function open_session()
local media_room_LG_key = "520850"
local media_room_LG_ip = "192.168.1.233:8080"
local log_msg = "here"

local http = require("socket.http")
local ltn12 = require("ltn12")

local respBody = {}
local req_url = "http://"..media_room_LG_ip.."/roap/api/auth"
local output1 = ""
local payload = "<auth><type>AuthKeyReq</type></auth>"
local rBody, rCode, rHeaders, rStatus = http.request(
	{
		url = req_url,
                method = "POST",
		headers = { ["Content-Type"] = "application/atom+xml; charset=utf-8" },
		source = ltn12.source.string(payload),
                sink = ltn12.sink.table(rBody)
	}
       )
end

Any ideas? Do I need to do anything special because of the “atom+xml” content type? Do I have my “utf-8” definition in the right place?

Deleted

Figured it out.
I had to add content-length in the request.

Hi, how do you do to control the LG TV? Do you need anything special? If you could teach me I would appreciate it. Thanks.