1

I am trying to send raw xml to a service in Python. I have a the address of the service and my question is how would I wrap XML in python and send it to the service. The address is in the format below.

192.1100.2.2:54239

And say the XML is:

<xml version="1.0" encoding="UTF-8"><header/><body><code><body/>

Anyone know what to do?

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
user314644
  • 13
  • 1
  • 3

2 Answers2

7

This should do the trick.

import socket
import time

command = '<xml version="1.0" encoding="UTF-8"><header/><body><code><body/>'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.1100.2.2", 54239))

s.send(command)

time.sleep(2)
resp = s.recv(3000)

print resp
chrisg
  • 40,337
  • 38
  • 86
  • 107
1
pydoc socket

... should get you started.

PS. Your example IP address looks a bit strange (1100 is greater than 255), but maybe that's just so nobody tries to use it ...

Rasmus Kaj
  • 4,224
  • 1
  • 20
  • 23