欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂Python培訓(xùn)分享Python搭建簡單的http server 可直接post文件的實例

2019-03-01 13:26:02 1867瀏覽

Python開發(fā)技術(shù)自從誕生以來就備受人們的關(guān)注與喜愛,所以如今參加Python培訓(xùn)學(xué)習(xí)Python開發(fā)技術(shù)的小伙伴越來越多,本篇文章小編就和大家分享一篇Python 搭建簡單的http server,可直接post文件的實例,希望對小伙伴們有所幫助。



扣丁學(xué)堂Python培訓(xùn)分享Python搭建簡單的http server 可直接post文件的實例



server:


#coding=utf-8
from BaseHTTPServer import BaseHTTPRequestHandler
import cgi
class PostHandler(BaseHTTPRequestHandler):
 def do_POST(self):
  form = cgi.FieldStorage(
   fp=self.rfile,
   headers=self.headers,
   environ={'REQUEST_METHOD':'POST',
      'CONTENT_TYPE':self.headers['Content-Type'],
      }
  )
  self.send_response(200)
  self.end_headers()
  self.wfile.write('Client: %sn ' % str(self.client_address) )
  self.wfile.write('User-agent: %sn' % str(self.headers['user-agent']))
  self.wfile.write('Path: %sn'%self.path)
  self.wfile.write('Form data:n')
  for field in form.keys():
   field_item = form[field]
   filename = field_item.filename
   filevalue = field_item.value
   filesize = len(filevalue)#文件大小(字節(jié))
   #print len(filevalue)
	 #print (filename)
   with open(filename.decode('utf-8'),'wb') as f:
    f.write(filevalue)
  return
 
def StartServer():
 from BaseHTTPServer import HTTPServer
 sever = HTTPServer(("",8080),PostHandler)
 sever.serve_forever()
 
 
 
 
if __name__=='__main__':
 StartServer()


client:


#coding=utf-8
import requests
url = "http://172.16.1.101:8080"
path = "/home/ly/ly.exe"
print path
files = {'file': open(path, 'rb')}
r = requests.post(url, files=files)
print (r.url)
print (r.text)


以上就是扣丁學(xué)堂Python在線學(xué)習(xí)小編給大家分享的Python搭建簡單的http server 可直接post文件的實例,希望對小伙伴們有所幫助,想要了解更多內(nèi)容的小伙伴可以登錄扣丁學(xué)堂官網(wǎng)咨詢。



想要學(xué)好Python開發(fā)小編給大家推薦口碑良好的扣丁學(xué)堂,扣丁學(xué)堂有專業(yè)老師制定的Python學(xué)習(xí)路線圖輔助學(xué)員學(xué)習(xí),此外還有與時俱進的Python課程體系和Python視頻直播課供大家學(xué)習(xí),想要學(xué)好Python開發(fā)技術(shù)的小伙伴快快行動吧。扣丁學(xué)堂Python技術(shù)交流群:279521237。


扣丁學(xué)堂微信公眾號 


關(guān)注微信公眾號獲取更多學(xué)習(xí)資料 


 

查看更多關(guān)于"Python開發(fā)資訊"的相關(guān)文章>




標(biāo)簽: Python培訓(xùn) Python視頻教程 Python在線視頻 Python學(xué)習(xí)視頻 Python培訓(xùn)班

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部