Can anyone good at Python and/or Xojo HTTPSockets help figure this out?

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.

payload = {‘key1’: ‘value1’, ‘key2’: ‘value2’}
response = requests.post(“http://myapp.com/post”, data=payload)

You have “soap” set in some place of your python code as you have “headers”.

And as for content: HTTPSocket.SetRequestContent ( Content as String, ContentType as String )

This is the part I don’t understand at all. Do I pass the ‘soap’ variable as the Content? What is the ContentType??

HTTPSocket.SetRequestContent ( payload, “text/xml” )

Cool. That makes sense.

Thanks