python解析post請(qǐng)求 如何用python寫后臺(tái)接收客戶端發(fā)送的post請(qǐng)求?
如何用python寫后臺(tái)接收客戶端發(fā)送的post請(qǐng)求?Import urllib2import urllib#定義要提交的數(shù)據(jù)數(shù)組(字典)。Data={}Data[“username”]=“zgx03
如何用python寫后臺(tái)接收客戶端發(fā)送的post請(qǐng)求?
Import urllib2import urllib#定義要提交的數(shù)據(jù)數(shù)組(字典)。Data={}Data[“username”]=“zgx030030”Data[“password”]=“123456”#定義郵寄地址。Url=“test.com/post/“發(fā)布數(shù)據(jù)=urllib.urlencode文件(數(shù)據(jù))#提交,發(fā)送數(shù)據(jù)請(qǐng)求=urllib2。Urlopen(URL,post)35; Data)#獲取提交后返回的信息內(nèi)容=請(qǐng)求讀?。ǎ?/p>
python怎么發(fā)送post請(qǐng)求?
我使用Python 3.5,代碼如下:
來自u(píng)rllib.parse文件導(dǎo)入urlencodefromurllib.request請(qǐng)求導(dǎo)入urlopendef send to server(url,post data=None):如果post data:para=urlencode(post data)page=urlopen(url段落編碼(“UTF-8”)?注意,如果您不在這里編碼,您將報(bào)告一個(gè)錯(cuò)誤:page=urlopen(URL)return(第頁。閱讀().解碼(“utf-8”)