一、
#!/usr/bin/env python
import httplib, urllib
params = urllib.urlencode({'connectname': 'u',
'connecttype': -1,
'consumeright': 0,
'separatecard': 0,
'localip': '192.168.000.000',
'IsIndex': 0,
'username': 88888888,
'password': 8888})
headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla',
'Content-Type': 'application/x-www-form-urlencoded'}
server = '61.61.61.61'
path = '/secu/webLogin.jsp'
conn = httplib.HTTPConnection(server)
conn.request("POST", path, params, headers)
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
print data1
conn.close()
二、
#!/usr/bin/env python
import httplib
def testHttplib(server, path):
req = httplib.HTTP(server)
req.putrequest('GET', path)
req.putheader('Accept', 'text/html')
req.putheader('User-Agent', 'Mozilla')
req.endheaders()
ec, em, h = req.getreply()
fd = req.getfile()
return fd.read(), (ec, em)
myip = '192.168.000.000'
server = '61.61.61.61'
path = '/ClientProcess.jsp?MsgType=1&ISNNO=1001&LocalIP=' + myip
# print 'testing "%s%s"' % (server, path)
dataHttplib, result = testHttplib(server, path)
# print "data length (httplib):", len(dataHttplib), result
# print dataHttplib
三、
# loginbbs.py
import urllib,httplib
#此处为要post的登陆参数,你可以修改为你自己的参数
params = urllib.urlencode({''''username'''':''''pytest'''',
''''password'''':''''pypassword'''',
''''Cookies_Time'''': 1,
''''IsLogin'''':True})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
#构建headers
conn = httplib.HTTPConnection("music.popv.net:80") #建立http连接,记得地址不要加''''http://''''且要加上port;
conn.request("POST", params, headers)
#发送登陆请求
response = conn.getresponse()#获得回复
print response.status, response.reason#获得请求状态
data = response.read()#获得登陆后的网页内容
conn.close()#关闭连接
阅读(1124) | 评论(0) | 转发(0) |