Transferred from: http://www.045d.com/post/671.html
Code:
1 ImportUrllib22 3data =" "<xml>4 <tousername><! [cdata[touser]]></tousername>5 <fromusername><! [cdata[fromuser]]></fromusername>6 <CreateTime>1348831860</CreateTime>7 <msgtype><! [cdata[text]]></msgtype>8 <content><! [cdata[The content you want to test]]></content>9 <MsgId>1234567890123456</MsgId>Ten </xml>" " One Acookies =Urllib2. Httpcookieprocessor () -Opener =Urllib2.build_opener (Cookies) - theRequest =Urllib2. Request ( -URL = r'http://gyt8.sinaapp.com/weixin?signature=1ce507b0abfa4d231b538988c01127c9e03a02ad×tamp=1408377801 &nonce=959202980', -headers = {'Content-type':'Text/xml'}, -data =data) + - PrintOpener.open (Request). Read ()
The effect is as follows:
<xml> <tousername><! [cdata[fromuser]]></tousername> <fromusername><! [cdata[touser]]></fromusername> <CreateTime>1408382536</CreateTime> <msgtype><! [cdata[text]]></msgtype> <content><! [cdata[site is in emergency maintenance, please look forward to]]></content> </xml>
Python POST XML