开发者

How to send raw XML in Python?

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?


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


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 ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜