I’m trying to port this Python class to Xojo to control my Sonos music system.
My Python is awful. Here’s the part of the method that I’m struggling with:
r = requests.post('http://' + self.speaker_ip + ':1400' + endpoint, data=soap, headers=headers)
Where r, endpoint, soap and headers are all strings. requests is an imported Python module of the same name (I think to make HTTP requests simpler).
Python code:
headers = {
'Content-Type': 'text/xml',
'SOAPACTION': action
}
Xojo translation (I think!):
MyHTTPSocket.ClearRequestHeaders()
MyHTTPSocket.SetRequestHeader("Content-Type", "text/xml")
MyHTTPSocket.SetRequestHeader("SOAPACTION", action)
What I’m struggling with is how to implement the POST request. I can do this:
response = MyHTTPSocket.Post("http://" + speakerIP + ":1400" + endpoint)
and obviously I’ve set the headers (see above) but where do I add ‘soap’? Do I use something like:
HTTP.SetRequestContent()
and if so, what would Content and ContentType be (see docs)?
Thanks if anybody can help.