GET:

  1. #lianxi-httplib.HTTPConnection.request-get.py
  2.  
  3. import httplib
  4.  
  5. class HttpRequestGETTest(object):
  6. def __init__(self):
  7. #self.body='{"UserName":"Admin","Password":"693aa8d0806c532115637809a863b1a3","sessionID":""}'
  8. self.headers = {
  9. "Referer": '192.168.1.1',
  10. "Accept-Encoding": "gzip, deflate,sdch",
  11. "Connection":"Keep-Alive"}
  12.  
  13. def http_get(self):
  14. conn=httplib.HTTPConnection(host='192.168.1.1', port=80, strict=False, timeout=30)
  15. conn.request(method='GET',url='/cgi-bin/GetLoginStatus?sessionID=undefined', body=None, headers=self.headers)
  16. a = conn.getresponse().read()
  17. print a
  18.  
  19. lianxi=HttpRequestGETTest()
  20. lianxi.http_get()

POST:

  1. #lianxi-httplib.HTTPConnection.request-post.py
  2.  
  3. import httplib
  4.  
  5. class HttpRequestPOSTTest(object):
  6. def __init__(self):
  7. self.body='{"UserName":"Admin","Password":"693aa8d0806c532115637809a863b1a3","sessionID":""}'
  8. self.headers = {
  9. "Referer": '192.168.1.1',
  10. "Accept-Encoding": "gzip, deflate,sdch",
  11. "Connection":"Keep-Alive"}
  12.  
  13. def http_post(self):
  14. conn=httplib.HTTPConnection(host='192.168.1.1', port=80, strict=False, timeout=120)
  15. conn.request(method='POST',url='/cgi-bin/Login', body=self.body, headers=self.headers)
  16. self.session_id = conn.getresponse().read()
  17. print self.session_id
  18.  
  19. lianxi=HttpRequestPOSTTest()
  20. lianxi.http_post()

python模块httplib的使用的更多相关文章

  1. python用httplib模块发送get和post请求

    在python中,模拟http客户端发送get和post请求,主要用httplib模块的功能. 1.python发送GET请求 我在本地建立一个测试环境,test.php的内容就是输出一句话: 1 e ...

  2. Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 httplib模块 django和web服务器整合 wsgi模块 gunicorn模块

    Python第十三天   django 1.6   导入模板   定义数据模型   访问数据库   GET和POST方法    SimpleCMDB项目   urllib模块   urllib2模块 ...

  3. python模块之httplib(在py3中功能进一步强大,请详看文档)

    # -*- coding: utf-8 -*-#python 27#xiaodeng#python模块之httplib(在py3中功能进一步强大,请详看文档) import httplib#是较为底层 ...

  4. python模块介绍- multi-mechanize 性能测试工具

    python模块介绍- multi-mechanize 性能测试工具 2013-09-13 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq 3739 ...

  5. python模块大全

    python模块大全2018年01月25日 13:38:55 mcj1314bb 阅读数:3049 pymatgen multidict yarl regex gvar tifffile jupyte ...

  6. python urllib2 httplib HTTPConnection

    httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,urllib2)使用了它的http实现. import httplib conn  ...

  7. 使用C/C++写Python模块

    最近看开源项目时学习了一下用C/C++写python模块,顺便把学习进行一下总结,废话少说直接开始: 环境:windows.python2.78.VS2010或MingW 1 创建VC工程 (1) 打 ...

  8. Python模块之configpraser

    Python模块之configpraser   一. configpraser简介 用于处理特定格式的文件,其本质还是利用open来操作文件. 配置文件的格式: 使用"[]"内包含 ...

  9. Python模块之"prettytable"

    Python模块之"prettytable" 摘要: Python通过prettytable模块可以将输出内容如表格方式整齐的输出.(对于用Python操作数据库会经常用到) 1. ...

随机推荐

  1. Map拷贝 关于对象深拷贝 浅拷贝的问题

    问题:map拷贝时发现数据会变化. 高能预警,你看到的下面的栗子是不正确的,后面有正确的一种办法,如果需要看的话的,请看到底,感谢各同学的提醒,已做更正,一定要看到最后      先看例子:     ...

  2. linux下安装mysql5.7.17及简单配置

    原文:http://www.th7.cn/db/mysql/201612/218745.shtml 1.mysql5.7.17安装在/usr/local/mysql目录里面,也可以安装在其他地方 (安 ...

  3. int(3)和int(10)的区别

    int(M) 在 integer 数据类型中,M 表示最大显示宽度.在 int(M) 中,M 的值跟 int(M) 所占多少存储空间并无任何关系. int(3).int(4).int(8) 在磁盘上都 ...

  4. vue 2.0

    vue2.0 据说也出了很久了,博主终于操了一次实刀. 整体项目采用  vue +  vue-router +  vuex (传说中的vue 全家桶 ),构建工具使用尤大大推出的vue-cli 项目是 ...

  5. ie8下背景图片平铺问题

    IE9+及其他浏览器实现背景图片平铺可能需要一个属性就可以background-size:100%/cover; 但是ie8下background-size是不兼容的,因此我们需要用到滤镜,来解决背景 ...

  6. Sprint1(第二天11.15)

    Sprint1(第二天11.15) Sprint1第一阶段 1.类名:软件工程-第一阶段 2.时间:11.14-11.23 3.选题内容:web版-餐厅到店点餐系统 4.团队博客地址: http:// ...

  7. n进制转化成十进制

    一个字节是8位二进制. 我的天啊.我发现char特别厉害: char类型能够输入整形常量.不能超过-128~127. 只能是整数类型,且范围一般不能超出-128~127.超出会溢出的.

  8. Java中sql语句的引号问题

    1..sql语句 在数据库中,当我们查询语句时,会使用类似的语句: Select * from userinfo where userid='1' or 1; Select * from userin ...

  9. android .9图的作用

    参考:http://www.cnblogs.com/lianghui66/archive/2013/01/08/2850581.html .9图的介绍 1.这种格式的图片是Android平台上一种被拉 ...

  10. textbox button 模拟fileupload

    方案一:  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.asp ...