標籤:
轉自:http://www.045d.com/post/671.html
代碼:
1 import urllib2 2 3 data = ‘‘‘<xml> 4 <ToUserName><![CDATA[toUser]]></ToUserName> 5 <FromUserName><![CDATA[fromUser]]></FromUserName> 6 <CreateTime>1348831860</CreateTime> 7 <MsgType><![CDATA[text]]></MsgType> 8 <Content><![CDATA[你要測試的內容]]></Content> 9 <MsgId>1234567890123456</MsgId>10 </xml>‘‘‘11 12 cookies = urllib2.HTTPCookieProcessor()13 opener = urllib2.build_opener(cookies)14 15 request = urllib2.Request(16 url = r‘http://gyt8.sinaapp.com/weixin?signature=1ce507b0abfa4d231b538988c01127c9e03a02ad×tamp=1408377801&nonce=959202980‘,17 headers = {‘Content-Type‘ : ‘text/xml‘},18 data = data)19 20 print opener.open(request).read()
效果如下:
<xml> <ToUserName><![CDATA[fromUser]]></ToUserName> <FromUserName><![CDATA[toUser]]></FromUserName> <CreateTime>1408382536</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[網站正在緊急維護中,敬請期待]]></Content> </xml>
python POST XML