1. 程式人生 > >Python之POST登錄測試

Python之POST登錄測試

name pycharm stat bad ons user con 解析 blog

不解釋,直接上代碼:

 1 #!/usr/bin/env python  
 2 # -*- encoding: utf-8 -*-
 3 
 4 """ 
 5 @version: v1.0 
 6 @author: elijahxb
 7 @OS: linux
 8 @contact: [email protected] 
 9 @site: http://www.cnblogs.com/elijahxb 
10 @software: PyCharm Community Edition 
11 @file: zhangye.py 
12 @time: 17-7-2 下午12:16 
13
""" 14 15 ‘‘‘ 16 本次登錄測試: 17 USERNAME:test001_001 18 PASSWORD:test001 19 URL: http://www.zhangye.ccoo.cn/ 20 TYPE: POST 21 HOST: www.zhangye.ccoo.cn 22 POSTURL:http://www.zhangye.ccoo.cn/login9.asp 23 POSTDATA:username=test001_001&password=test001 24 ‘‘‘ 25 import httplib 26 import urllib 27 28 HOST = 182.92.232.234
29 SOURCEURL = "http://www.zhangye.ccoo.cn/" 30 POSTURL = http://www.zhangye.ccoo.cn/login9.asp 31 PORT = 80 32 STRICT = False # 默認False,表示無法解析服務器返回的狀態行時,是否拋出BadStatusLine異常 33 TIMEOUT = 5 34 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) 43 44 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.status 51 print response.reason 52 print response.read() 53 print response.getheaders() 54 except Exception, e: 55 print e 56 finally: 57 if HttpClient: 58 HttpClient.close()

Python之POST登錄測試