python模块httplib的使用

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()

 

posted on 2016-09-26 14:58  懒懒的小猪 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lldxz/p/5909221.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值