欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Python之POST登录实例代码

程序员文章站 2022-04-06 18:50:25
...
不解释,直接上代码:
 1 #!/usr/bin/env python   
 2 # -*- encoding: utf-8 -*- 3  
 4 """  
 5 @version: v1.0 
 6 @author: elijahxb 7 @OS: linux 8 @contact: elijahxb@163.com 
 9 @site:  
10 @software: PyCharm Community Edition 
11 @file: zhangye.py 
12 @time: 17-7-2 下午12:16 
13 """14 15 '''16 本次登录测试:17 USERNAME:test001_00118 PASSWORD:test00119 URL:   
20 TYPE:  POST21 HOST:  www.zhangye.ccoo.cn22 POSTURL:
23 POSTDATA:username=test001_001&password=test00124 '''
25 import httplib26 import urllib27 28 HOST = '182.92.232.234'
29 SOURCEURL = ""30 POSTURL = ''
31 PORT = 8032 STRICT = False  
# 默认False,表示无法解析服务器返回的状态行时,是否抛出BadStatusLine异常
33 TIMEOUT = 534 HEADERS = {
35     'Content-type': 'application/x-www-form-urlencoded',
36     "Accept": "*/*"37 }38 TestDATA = {39     'username': 'test001_001',
40     'password': 'test001'41 }42 TestDATA = urllib.urlencode(TestDATA)
try:45     # Conn = httplib.HTTPConnection(HOST, PORT, STRICT, TIMEOUT, SOURCEURL)46    
HttpClient = httplib.HTTPConnection(HOST)47     
HttpClient.request('POST', POSTURL, TestDATA, HEADERS)48 49     
response = HttpClient.getresponse()50     print response.status51     
print response.reason52     print response.read()53     
print response.getheaders()54 except Exception, e:55     
print e56 finally:57     if HttpClient:58         
HttpClient.close()

以上就是Python之POST登录实例代码的详细内容,更多请关注其它相关文章!