如何用PYTHON的CGIHTTPSERVER模块模拟POST请求?
这次又要逼真一点点,可以弄POST请求啦。
在WEB根目录下新建cgi-bin目录(据说是规模要求),然后运行命令:
python -m CGIHTTPServer
CGI-BIN目录下,form.py处理POST请求的内容(简化到不行):
# -*- coding: utf-8 -*-
import cgi
header = 'Content-Type: text/html\n\n'
html = '<h3>接受处理表单数据\n</h3>'
#打印返回的内容
#print header
#print html
# 接受表达提交的数据
form = cgi.FieldStorage()
#print '接收表达get的数据 :',form
print '<p />'
# 解析处理提交的数据
content = form['userName'].value
print content, '$$$$$$$$$$$$$'
formhtml = '''
%s
'''
print formhtml % ('登陆成功')
然后,就可以测试EXTJS中的提交表单更新HTML元素啦。
<!DOCTYPE html>
<html>
<head>
<title>ExtJs</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="ExtJs/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css">
<script type="text/javascript" src="ExtJs/ext-all.js"></script>
<script type="text/javascript" src="ExtJs/bootstrap.js"></script>
<script type="text/javascript" src="ExtJs/packages/ext-theme-crisp/build/ext-theme-crisp.js"></script>
<script type="text/javascript">
Ext.onReady(function(){
var loader = Ext.get("loginMsg").getLoader();
Ext.get('loginBtn').on('click', login);
function login(){
loader.load({
form: "loginForm",
url: '/cgi-bin/form.py'
});
}
});
</script>
</head>
<body style="margin: 20px">
<form id="loginForm">
用户名:<input name="userName" type="text">
密码:<input name="password" type="password">
<input type="button" value="登陆" id="loginBtn">
</form>
状态:<span id="loginMsg"></span>
</body>
</html>

如何用PYTHON的CGIHTTPSERVER模块模拟POST请求?的更多相关文章
- python利用requests库模拟post请求时json的使用
我们都见识过requests库在静态网页的爬取上展现的威力,我们日常见得最多的为get和post请求,他们最大的区别在于安全性上: 1.GET是通过URL方式请求,可以直接看到,明文传输. 2.POS ...
- 用python的Requests库模拟http请求
一.先了解几个重要的http请求头或响应头信息 Request Headers: Host: 描述请求将被发送的目的地,包括,且仅仅包括域名和端口号. Origin: 说明请求从哪里发起的,包括,且仅 ...
- Python 使用matplotlib模块模拟掷骰子
掷骰子 骰子类 # die.py 骰子类模块 from random import randint class Die(): """骰子类""&quo ...
- python用random模块模拟抽奖逻辑(print修改end参数使打印结果不分行)
import random #引入random模块,运用random函数list_one=["10081","10082","10083" ...
- python使用requests模块模拟登陆知乎
from bs4 import BeautifulSoup import requests import time def captcha(captcha_data): with open(" ...
- 基于python第三方requests 模块的HTTP请求类
使用requests模块构造的下载器,首先安装第三方库requests pip install requests 1 class StrongDownload(object): def __init_ ...
- python 爬虫 urllib模块 发起post请求
urllib模块发起的POST请求 案例:爬取百度翻译的翻译结果 1.通过浏览器捉包工具,找到POST请求的url 针对ajax页面请求的所对应url获取,需要用到浏览器的捉包工具.查看百度翻译针对某 ...
- python中Requests模块中https请求在设置为忽略有效性验证,屏蔽告警信息的方式
增加下面的就ok了from requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.ur ...
- Python爬虫3-parse编码与利用parse模拟post请求
GitHub代码练习地址:①利用parse模拟post请求:https://github.com/Neo-ML/PythonPractice/blob/master/SpiderPrac04_pars ...
随机推荐
- oc40--类的启动过程
// // main.m // 类的启动过程 #import <Foundation/Foundation.h> #import "Person.h" #import ...
- How to use shared model by git in sql source control of red gate
1.clone the git repository for datbase 2.open sql source control window and select the target databa ...
- multiple web application host under the same website on IIS (authentication mode)
第一种方式,修改forms的name how to set the forms authentication cookie path assume you have already solved th ...
- dynamic关键字的使用
https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonConvert.htm 在使用DeserializeObject函数进行 ...
- Codeforces--630C--Lucky Numbers(快速幂)
C - Lucky Numbers Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536K ...
- Principal Component Analysis ---- PRML读书笔记
To summarize, principal component analysis involves evaluating the mean x and the covariance matrix ...
- 91. ExtJS获取父子、兄弟容器元素方法
转自:https://blog.csdn.net/u014745818/article/details/44957341 1 1.当前对象的父对象(上级对象) this.ownerCt: 2.当前对象 ...
- jFinal基于maven简单的demo
JFinal 是基于Java 语言的极速 web 开发框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩展.Restful.在拥有Java语言所有优势的同时再拥有ruby.py ...
- Blender插件初始化范例
目标 [x] 总结Blender插件初始化范例 总结 插件模板 Blender内部插件实现方式模板功能总结如下: 定义了子模块重加载方式 定义了批量加载子模块的方式 插件注册函数 插件注销函数 模块总 ...
- UOJ 129/BZOJ 4197 寿司晚宴 状压DP
//By SiriusRen #include <cstdio> #include <algorithm> using namespace std; ; struct Node ...