Skip to content

Instantly share code, notes, and snippets.

@gtt116
Last active August 29, 2015 14:05
Show Gist options
  • Save gtt116/4b26499b86ebf0ffc2b1 to your computer and use it in GitHub Desktop.
Save gtt116/4b26499b86ebf0ffc2b1 to your computer and use it in GitHub Desktop.
python http handler
#coding=gbk
from httplib import HTTPConnection,HTTPResponse
# request' header
headers = {
"User-Agent":"Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language":"zh-cn,zh;q=0.5",
"Accept-Charset":"GB2312,utf-8;q=0.7,*;q=0.7",
"Keep-Alive":"115",
"Connection":"keep-alive",
"Content-Type":"application/x-www-form-urlencoded",
}
username= "53521"
password="53521"
data = "number=%s&passwd=%s&select=cert_no&returnUrl=" % (username,password)
conn = HTTPConnection("210.33.91.65:8080")
conn.request("POST",url="/reader/redr_verify.php",body=data,headers=headers)
res = conn.getresponse()
if res.status == 302:print 'ok'
else: print 'err'
import urllib2
#目标网址:url = http://www.google.com
#要发送的头部head
#要发送的数据data
req = urllib2.Request(url)
req.add_header(head)
req.add_data(data)
resp = urllib2.urlopen(req)
resp.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment