GET:
1 #Lianxi-httplib. httpconnection.request-get.py2 3 ImportHttplib4 5 classHttprequestgettest (object):6 def __init__(self):7 #self.body= ' {"UserName": "Admin", "Password": "693aa8d0806c532115637809a863b1a3", "SessionID": "} '8Self.headers = {9 "Referer":'192.168.1.1',Ten "accept-encoding":"gzip, DEFLATE,SDCH", One "Connection":"keep-alive"} A - defHttp_get (self): -Conn=httplib. Httpconnection (host='192.168.1.1', port=80, Strict=false, timeout=30) theConn.request (method='GET', url='/cgi-bin/getloginstatus?sessionid=undefined', Body=none, headers=self.headers) -A =conn.getresponse (). Read () - Printa - +Lianxi=httprequestgettest () -Lianxi.http_get ()
POST:
1 #Lianxi-httplib. httpconnection.request-post.py2 3 ImportHttplib4 5 classHttprequestposttest (object):6 def __init__(self):7self.body='{"UserName": "Admin", "Password": "693aa8d0806c532115637809a863b1a3", "SessionID": ""}'8Self.headers = {9 "Referer":'192.168.1.1',Ten "accept-encoding":"gzip, DEFLATE,SDCH", One "Connection":"keep-alive"} A - defHttp_post (self): -Conn=httplib. Httpconnection (host='192.168.1.1', port=80, Strict=false, timeout=120) theConn.request (method='POST', url='/cgi-bin/login', Body=self.body, headers=self.headers) -self.session_id =conn.getresponse (). Read () - Printself.session_id - +Lianxi=httprequestposttest () -Lianxi.http_post ()
Use of Python module httplib