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.

Post Request with XML request body
#1
I am trying to send the following command to SONY Bravia TV with REST API request.
While I successfully sent the exact same command with XML request body with Postman,
when I try with LM I am getting 500 Internal Server Error.
Am I missing something in my code?

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

path =  'http://172.16.1.11/sony/ircc'
payload = [[<?xml version="1.0"?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <s:Body>
        <u:X_SendIRCC
            xmlns:u="urn:schemas-sony-com:service:IRCC:1">
            <IRCCCode>AAAAAgAAAJcAAAArAw==</IRCCCode>
        </u:X_SendIRCC>
    </s:Body>
</s:Envelope>]]

local response_body = { }
local res, code, response_headers, status = http.request
{
    url = path,
    method = "POST",
    headers =
    {
      ["Accept"] = "*/*",
      ["Host"] = "172.16.1.1",
      ["Content-Type"] = "application/xml",
      ["SOAPACTION"] = "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC",
      ["X-Auth-PSK"] = "1707",
      ["Connection"] = "Keep-Alive",
      ["Content-Length"] = payload:len()
    },
   
    source = ltn12.source.string(payload),       
    sink = ltn12.sink.table(response_body)
}
log("Response:", table.concat(response_body))
log("Status:", status)
log("Code:", code)
log("Response Headers:", response_headers)
log("Result:", res)




The example code from SONY Bravia official is the follwoing.
https://pro-bravia.sony.net/ja/develop/i...entication

Thank you for your help in advance!
Reply
#2
Host header is not needed (it also does not match the IP of your TV).
Content-Type is different from the docs, should be text/xml; charset=UTF-8
Also try removing ["Connection"] = "Keep-Alive", as it's not supported by the library.

If it still does not work the try exporting Postman request that works in Curl format and post it here.
Reply
#3
Thank you admin!
I removed Host, Connection headers and changed Content-Type but it is not working...

This is the Curl request that works successfully.


Code:
curl --location 'http://172.16.1.11/sony/ircc' \
--header 'X-Auth-PSK: 1707' \
--header 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' \
--header 'Content-Type: application/xml' \
--data '<?xml version="1.0"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:X_SendIRCC
xmlns:u="urn:schemas-sony-com:service:IRCC:1">
<IRCCCode>AAAAAgAAAKQAAABbAw==</IRCCCode>
</u:X_SendIRCC>
</s:Body>
</s:Envelope>'
Reply
#4
Looks like SOAPACTION header value must be also contain double quotes:
Code:
["SOAPACTION"] = [["urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"]],

Not sure if it matters but your script has a different IRCCCode value compared to the Postman/Curl.
Reply
#5
Ohhh exactly, it worked ..... !!
Thank you so much for your quick help!!
Oh yes I am trying with several IRCCCode but they all work now....appreciate you a lot as always!
Reply


Forum Jump: