设置连接:在python中使用mechanize保持活动状态

时间:2015-10-31 05:29:15

标签: python mechanize

我正在尝试发送一个应包含

的HTTP标头
Connection:keep-alive

但是当我使用:

添加标题时
br = mechanize.Browser()
br.addheaders[('Connection','keep-alive')'''and some other headers''']

并使用Fiddler4发送请求并分析发送的标头,我得到连接状态:

Connection:'close'

如何才能让会议保持活力

这是我试图用python mechanize发送的标题,结果是

HTTPError:HTTP错误408:请求超时

POST http://site21.way2sms.com/smstoss.action HTTP/1.1
Origin: http://site21.way2sms.com
Content-Length: 94
Accept-Language: en-US,en;q=0.8
Accept-Encoding: gzip, deflate
Connection: close
Accept:      text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
Host: site21.way2sms.com
Referer: http://site21.way2sms.com/sendSMS?    Token=4A0CB0CC3FD1F0EE7985FFB44E04C6B7.w814
Cache-Control: max-age=0
Cookie: _gat=1; JSESSIONID=A08~4A0CB0CC3FD1F0EE7985FFB44E04C6B7.w814;  _ga=GA1.2.1739915090.1432824367
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Content-Type: application/x-www-form-urlencoded

ssaction=ss&Token=4A0CB0CC3FD1F0EE7985FFB44E04C6B7.w814&mobile=9765272851&message=6&msgLen=139

这是浏览器发送的标题,显示预期的结果:

POST http://site21.way2sms.com/smstoss.action HTTP/1.1
Host: site21.way2sms.com
Connection: keep-alive
Content-Length: 94
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://site21.way2sms.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML,   like Gecko) Chrome/46.0.2490.80 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://site21.way2sms.com/sendSMS?   Token=877AAB22C3F0B1C3D15F71C04C8AB85C.w804
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: _gat=1; JSESSIONID=A04~877AAB22C3F0B1C3D15F71C04C8AB85C.w804;   _ga=GA1.2.1739915090.1432824367

         ssaction=ss&Token=877AAB22C3F0B1C3D15F71C04C8AB85C.w804&mobile=9765272851&message=3&msgLen=139

0 个答案:

没有答案