您的位置:首页 > 编程语言 > Python开发

python发送请求两种代理设置方式

2015-07-28 14:07 706 查看
1使用httplib时的设置方式

import httplib,urllib,urllib2;
params = urllib.urlencode({ 'param':"55B2A1EDA8B09D13",
'js_sfl':2,
'codetxt':'532832'});
headers = { "Host": "www.aokang.cn",
"Content-Length": "81",
"Content-Type": "application/x-www-form-urlencoded"};
conn = httplib.HTTPConnection("localhost",8555);#在此步骤设置代理地址
conn.request(method="POST",url="http://www.aokang.cn/member/verify_repassword.aspx?action=edit HTTP/1.1",body=params,headers=headers);
response = conn.getresponse();
conn.close();


2使用urllib2时的设置方式

import httplib,urllib,urllib2;
params = urllib.urlencode({ 'param':"55B2A1EDA8B09D13",
'js_sfl':2,
'codetxt':'532832'});
headers = { "Host": "www.aokang.cn",
"Content-Length": "81",
"Content-Type": "application/x-www-form-urlencoded"};
opener = urllib2.build_opener( urllib2.ProxyHandler({'http':"localhost:8555"}) )#在这一步设置代理地址和端口
urllib2.install_opener(opener)
sContent = urllib2.urlopen("http://www.aokang.cn/member/verify_repassword.aspx?action=edit HTTP/1.1")
req = urllib2.Request(url = "http://www.aokang.cn/member/verify_repassword.aspx?action=edit HTTP/1.1",data=params)


这样就可以在burp中观察不同请求变化
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息