• 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()
  • 相关阅读:
    目前加尼福尼亚自动驾驶公司测试公司————20150529
    DDR3
    Linux mysql 5.7: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    macOS 10.12,解决如何打开隐私中的任何来源方法
    git查看某个文件的提交历史
    ios-deploy命令
    sed简用
    啊,栈溢出了
    二叉树题目总结(一)
    线段树(二)
  • 原文地址:https://www.cnblogs.com/lldxz/p/5909221.html
Copyright © 2020-2023  润新知