服务器代码:

from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
import cgi
import os class MyHTTPRequestHandler( BaseHTTPRequestHandler ): def do_GET( self ): pass def do_POST(self): form = cgi.FieldStorage( # cgi.FieldStorage实例效果类似一个字典,包含键-值和len等内置函数
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
print self.headers['Content-Type'] self.send_response(200)
self.end_headers()
self.wfile.write('Client: %s\n' % str(self.client_address))
# self.wfile.write('User-agent: %s\n' % str(self.headers['user-agent']))
# self.wfile.write('Path: %s\n' % self.path) params = {}
for field in form.keys():
params[field] = form[field].value fpth = params.get('f')
data = params.get('d')
code = params.get('c') try:
result = self.filesave(fpth, data, code)
except Exception, e:
result = 'Error in filesave:%s' % e
finally:
self.wfile.write(result) def filesave(self, fpth, data, code): if (fpth and data and code) is None:
return 'Params uncomplete!\n' path = '/'.join(fpth.split('/')[:-1])
name = fpth.split('/')[-1]
if not os.path.exists(path):
os.makedirs(path)
f = open(fpth, 'w')
f.write(data.encode(code))
f.close()
return 'Filesaved in %s' % fpth def do_HEAD( self ): pass if __name__ == '__main__': port = 28080
httpd = HTTPServer(('', port ), MyHTTPRequestHandler)
print "Server is running at port", port
httpd.serve_forever()

测试网页:

<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>
<title>百度一下,你就知道 </title>
<form name="f" id="s_ps_form" action="http://localhost:28080/" method="post" target='bbbb' > <input type="text" name="f" id="kw" maxlength="100" style="width:474px;" >
<input type="text" name="d" id="kw" maxlength="100" style="width:474px;" >
<input type="text" name="c" id="kw" maxlength="100" style="width:474px;" >
<input type="text" name="u" id="kw" maxlength="100" style="width:474px;" > <input type="submit" value="百度一下"> </form> <iframe name='bbbb'></iframe>

效果:

基于BaseHTTPServer的简单存储服务器的更多相关文章

  1. 基于modelsim-SE的简单仿真流程—下

    基于modelsim-SE的简单仿真流程—下 编译 在 WorkSpace 窗口的 counter_tst.v上点击右键,如果选择Compile selected 则编译选中的文件,Compile A ...

  2. 基于modelsim-SE的简单仿真流程—上

    基于modelsim-SE的简单仿真流程 编写RTL功能代码 要进行功能仿真,首先得用需要仿真的模块,也就是RTL功能代码,简称待测试的模块,该模块也就是在设计下载到FPGA的电路.一个电路模块想要有 ...

  3. [置顶] 使用红孩儿工具箱完成基于Cocos2d-x的简单游戏动画界面

    [Cocos2d-x相关教程来源于红孩儿的游戏编程之路CSDN博客地址:http://blog.csdn.net/honghaier 红孩儿Cocos2d-X学习园地QQ3群:205100149,47 ...

  4. 基于IndexedDB实现简单文件系统

    现在的indexedDB已经有几个成熟的库了,比如西面这几个,任何一个都是非常出色的. 用别人的东西好处是上手快,看文档就好,要是文档不太好,那就有点尴尬了. dexie.js :A Minimali ...

  5. .NetCore WebApi——基于JWT的简单身份认证与授权(Swagger)

    上接:.NetCore WebApi——Swagger简单配置 任何项目都有权限这一关键部分.比如我们有许多接口.有的接口允许任何人访问,另有一些接口需要认证身份之后才可以访问:以保证重要数据不会泄露 ...

  6. TOTP 介绍及基于C#的简单实现

    TOTP 介绍及基于C#的简单实现 Intro TOTP 是基于时间的一次性密码生成算法,它由 RFC 6238 定义.和基于事件的一次性密码生成算法不同 HOTP,TOTP 是基于时间的,它和 HO ...

  7. 一款基于css3的简单的鼠标悬停按钮

    今天给大家分享一款基于css3的简单的鼠标悬停按钮.这款悬停按钮鼠标经过前边框是间断的.当鼠标经过的时候边框间隔消失.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div ...

  8. R语言实战实现基于用户的简单的推荐系统(数量较少)

    R语言实战实现基于用户的简单的推荐系统(数量较少) a<-c(1,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,5,6,6,7,7) b<-c(1,2,3,4,2,3,4 ...

  9. Websocket - Websocket原理(握手、解密、加密)、基于Python实现简单示例

    一.Websocket原理(握手.解密.加密) WebSocket协议是基于TCP的一种新的协议.WebSocket最初在HTML5规范中被引用为TCP连接,作为基于TCP的套接字API的占位符.它实 ...

随机推荐

  1. linux下改变文件的字符编码

    首先确定文件的原始字符编码: $ file -bi test.txt 然后用 iconv 转换字符编码 $ iconv -f from-encoding -t to-encoding file > ...

  2. Spring AOP Interceptor transaction is not working

    Problem The Spring AOP transaction is not working in following interceptors? <bean id="testA ...

  3. HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...

  4. baseadapter.getItemId的使用方法:实现listview筛选、动态删除

    转载:http://www.lai18.com/content/1631131.html 这里的listview筛选是指listview的adapter实现filter来过滤数据. “动态删除&quo ...

  5. poj1459

    初涉网络流.改日再写一些概念性的介绍. ek算法可作为模板使用. #include <iostream> #include <queue> using namespace st ...

  6. .Net 揭密--JIT怎样运行你的代码

    方法调用: 第一部分 (普通调用) 译者:我们都知道.NET托管代码如C#.VB.NET写成的代码,都是先被编译成中间语言(IL,Intermediate Language,在运行时,再由即时编译器( ...

  7. Oracle新建用户、角色,授权,建表空间

    oracle数据库的权限系统分为系统权限与对象权限.系统权限( database system privilege )可以让用户执行特定的命令集.例如,create table权限允许用户创建表,gr ...

  8. V​M​W​a​r​e​里​安​装​6​4​位​L​i​n​u​x​ ​的​方​法

    1.CPU AMD系列的CPU略过 Intel系列的CPU芯片需要支持EM64T和VT技术才行,并且BIOS也要支持才可以. 为了确定你的Intel CPU是否支持VT,请查看: http://com ...

  9. Telnet端口测试

    $IP ="220.181.111.142"$Port ="801" Function Port-Test ($IP,$Port){ $Timeout = 10 ...

  10. 关于struts2 验证框架在联网的时候可以用,不联网不起作用的问题

    这是一个让我很头痛的问题,我是在一个其他的项目框架的基础上来开发新的项目. 当使用struts验证框架时,突然发现这个验证不起作用了,我就纳闷了之前用这个开发的项目好好的怎么到我这就不能用了呢? xm ...