python2发送http不编码_python模拟http请求2

发现了一个非常好用的第三方module:requests,模拟接口非常简单。

非常不错

#!coding:utf-8    相信这句大家都懂的,不解释

#导入需要的requests

import requests

#定义请求头

reqheaders={'Content-type':'application/x-www-form-urlencoded',  'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',  'Host':'www.renren.com',  'Origin':'http://zhichang.renren.com',  'Referer':'http://zhichang.renren.com',  'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1',}

#定义post的参数,requests模块,参数不用编码

reqdata={'email':'xxxx@xxx.com',  'password':'xxxx',  'autoLogin':'on',  'origURL':'http://zhichang.renren.com/?login_state=rr',  'domain':'renren.com' }

#模拟post请求,不让自动重定向

#模拟post请求,这个是自动重定向

#打印服务器返回的状态

print(res.status_code)

#打印服务器返回的内容

print(res.content)

#打印重定向的URL地址

print(res.headers['Location'])

#打印服务器返回的cookie

print(res.headers['Set-Cookie'])

以下是程序的运行结果

302

anonymid=hrt38gcmbjulj4; domain=.renren.com; path=/; expires=Sun, 17-Feb-2019 11:27:44 GMT, _de=97FB170A42B4342D1C47A157AD77AAFC1383380866D39FF5; domain=.renren.com; path=/; expires=Fri, 13-Feb-2015 11:27:44 GMT, p=31991a0a194c34e606ef1263317b06372; domain=renren.com; path=/; expires=Thu, 20-Mar-2014 11:27:44 GMT, ap=229996362; domain=renren.com; path=/; expires=Thu, 20-Mar-2014 11:27:44 GMT, first_login_flag=1; domain=renren.com; path=/, t=7f5cc046700354f79346b8b51f2361882; domain=.renren.com; path=/, t=b28114ad2246bad1b6b67f07b3b6c0a3; domain=renren.com; path=/xtalk/, societyguester=7f5cc046700354f79346b8b51f2361882; domain=.renren.com; path=/, id=229996362; domain=.renren.com; path=/, xnsid=bb3f9425; domain=.renren.com; path=/, loginfrom=syshome; domain=.renren.com; path=/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值