网站制作经典案例,广告公司简介简短大气,集团门户网站建设费用科目,网页加速器脚本目录
一、目标1#xff1a;GET数据包的处理
1、GET数据包中参数的提取
2、GET请求中 统计参数个数
二、目标2#xff1a;POST数据包的处理
1、post中参数个数的提取
2、POST请求中 统计参数个数 一、目标1#xff1a;GET数据包的处理
1、GET数据包中参数的提取
impo…目录
一、目标1GET数据包的处理
1、GET数据包中参数的提取
2、GET请求中 统计参数个数
二、目标2POST数据包的处理
1、post中参数个数的提取
2、POST请求中 统计参数个数 一、目标1GET数据包的处理
1、GET数据包中参数的提取
import redef extract_get_parameters(request):# 查找GET请求中的参数部分match re.search(rGET\s/.*\?(.*)\sHTTP, request)if match:parameters match.group(1)# 将参数部分按照 分割成键值对parameter_list parameters.split()# 将键值对解析为字典形式parameters_dict {}for parameter in parameter_list:key, value parameter.split()parameters_dict[key] valuereturn parameters_dictreturn {}# 示例请求
request GET /xxxx/xxxx HTTP/1.1\nHost: x.x.x.x.cn\n……{此处省略一万字}parameters extract_get_parameters(request)
print(parameters) 2、GET请求中 统计参数个数
import redef count_get_parameters(request):# 查找GET请求中的参数部分match re.search(rGET\s/.*\?(.*)\sHTTP, request)if match:parameters match.group(1)# 将参数部分按照 分割成键值对parameter_list parameters.split()# 统计参数个数return len(parameter_list)return 0# 示例请求
request GET /xxxx/xxxx HTTP/1.1\nHost: x.x.x.x.cn\n……{此处省略一万字}count count_get_parameters(request)
print(count) 二、目标2POST数据包的处理 1、post中参数个数的提取
import redef count_post_parameters(post_data):# 使用正则表达式提取JSON数据pattern r\{.*\}match re.search(pattern, post_data)if match:json_data match.group()parsed_data json.loads(json_data)parameter_count len(parsed_data)return parameter_countelse:return 0# 示例用法
post_data POST /xxxx/xxxx HTTP/1.1\nHost: x.x.x.x.cn\n……{此处省略一万字}parameter_count count_post_parameters(post_data)
print(parameter_count) # 输出4 2、POST请求中 统计参数个数
与GET类似就不再做叙述了