Python POST login test, pythonpost Login
Without explanation, go directly to the Code:
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: http://www.cnblogs.com/elijahxb 10 @ software: PyCharm Community Edition 11 @ file: zhangye. py 12 @ time: 17-7-2 "14 15 ''' 16 This login test: 17 USERNAME: test00000000118 PASSWORD: test00119 URL: http://www.zhangye.ccoo.cn/20 TYPE: POST21 HOST: www. zhangye. ccoo. cn22 POSTURL: http://www.zhangye.ccoo.cn/login9.asp23 POSTDATA: username = test000000001 & password = test00124 ''' 25 import httplib26 import urllib27 28 HOST = '2017. 92.232.234 '29 SOURCEURL = "http://www.zhangye.ccoo.cn/" 30 POSTURL = 'HTTP: // www.zhangye.ccoo.cn/login9.asp'31 PORT = 8032 STRICT = False # default False, indicating that the status row returned by the server cannot be resolved, whether to throw a BadStatusLine exception 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) 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. status51 print response. reason52 print response. read () 53 print response. getheaders () 54 failed t Exception, e: 55 print e56 finally: 57 if HttpClient: 58 HttpClient. close ()