Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29317471
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Python/Ruby

2009-05-15 09:39:10

一、
#!/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()#关闭连接
阅读(402) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~