标签:
转自: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>
标签:
原文地址:http://www.cnblogs.com/yinsua/p/4495594.html