搜索
首页后端开发Python教程Python之POST登录测试

Python之POST登录测试

Jul 03, 2017 pm 05:30 PM
postpython测试

不解释,直接上代码:

<span style="color: #008080"> 1</span> <span style="color: #008000">#</span><span style="color: #008000">!/usr/bin/env python  </span>
<span style="color: #008080"> 2</span> <span style="color: #008000">#</span><span style="color: #008000"> -*- encoding: utf-8 -*-</span>
<span style="color: #008080"> 3</span> 
<span style="color: #008080"> 4</span> <span style="color: #800000">"""</span> 
<span style="color: #008080"> 5</span> <span style="color: #800000">@version: v1.0 
</span><span style="color: #008080"> 6</span> <span style="color: #800000">@author: elijahxb
</span><span style="color: #008080"> 7</span> <span style="color: #800000">@OS: linux
</span><span style="color: #008080"> 8</span> <span style="color: #800000">@contact: elijahxb@163.com 
</span><span style="color: #008080"> 9</span> <span style="color: #800000">@site:  
</span><span style="color: #008080">10</span> <span style="color: #800000">@software: PyCharm Community Edition 
</span><span style="color: #008080">11</span> <span style="color: #800000">@file: zhangye.py 
</span><span style="color: #008080">12</span> <span style="color: #800000">@time: 17-7-2 下午12:16 
</span><span style="color: #008080">13</span> <span style="color: #800000">"""</span>
<span style="color: #008080">14</span> 
<span style="color: #008080">15</span> <span style="color: #800000">'''</span>
<span style="color: #008080">16</span> <span style="color: #800000">本次登录测试:
</span><span style="color: #008080">17</span> <span style="color: #800000">USERNAME:test001_001
</span><span style="color: #008080">18</span> <span style="color: #800000">PASSWORD:test001
</span><span style="color: #008080">19</span> <span style="color: #800000">URL:   
</span><span style="color: #008080">20</span> <span style="color: #800000">TYPE:  POST
</span><span style="color: #008080">21</span> <span style="color: #800000">HOST:  www.zhangye.ccoo.cn
</span><span style="color: #008080">22</span> <span style="color: #800000">POSTURL:
</span><span style="color: #008080">23</span> <span style="color: #800000">POSTDATA:username=test001_001&password=test001
</span><span style="color: #008080">24</span> <span style="color: #800000">'''</span>
<span style="color: #008080">25</span> <span style="color: #0000ff">import</span><span style="color: #000000"> httplib
</span><span style="color: #008080">26</span> <span style="color: #0000ff">import</span><span style="color: #000000"> urllib
</span><span style="color: #008080">27</span> 
<span style="color: #008080">28</span> HOST = <span style="color: #800000">'</span><span style="color: #800000">182.92.232.234</span><span style="color: #800000">'</span>
<span style="color: #008080">29</span> SOURCEURL = <span style="color: #800000">"</span><span style="color: #800000"></span><span style="color: #800000">"</span>
<span style="color: #008080">30</span> POSTURL = <span style="color: #800000">'</span><span style="color: #800000"></span><span style="color: #800000">'</span>
<span style="color: #008080">31</span> PORT = 80
<span style="color: #008080">32</span> STRICT = False  <span style="color: #008000">#</span><span style="color: #008000"> 默认False,表示无法解析服务器返回的状态行时,是否抛出BadStatusLine异常</span>
<span style="color: #008080">33</span> TIMEOUT = 5
<span style="color: #008080">34</span> HEADERS =<span style="color: #000000"> {
</span><span style="color: #008080">35</span>     <span style="color: #800000">'</span><span style="color: #800000">Content-type</span><span style="color: #800000">'</span>: <span style="color: #800000">'</span><span style="color: #800000">application/x-www-form-urlencoded</span><span style="color: #800000">'</span><span style="color: #000000">,
</span><span style="color: #008080">36</span>     <span style="color: #800000">"</span><span style="color: #800000">Accept</span><span style="color: #800000">"</span>: <span style="color: #800000">"</span><span style="color: #800000">*/*</span><span style="color: #800000">"</span>
<span style="color: #008080">37</span> <span style="color: #000000">}
</span><span style="color: #008080">38</span> TestDATA =<span style="color: #000000"> {
</span><span style="color: #008080">39</span>     <span style="color: #800000">'</span><span style="color: #800000">username</span><span style="color: #800000">'</span>: <span style="color: #800000">'</span><span style="color: #800000">test001_001</span><span style="color: #800000">'</span><span style="color: #000000">,
</span><span style="color: #008080">40</span>     <span style="color: #800000">'</span><span style="color: #800000">password</span><span style="color: #800000">'</span>: <span style="color: #800000">'</span><span style="color: #800000">test001</span><span style="color: #800000">'</span>
<span style="color: #008080">41</span> <span style="color: #000000">}
</span><span style="color: #008080">42</span> TestDATA =<span style="color: #000000"> urllib.urlencode(TestDATA)
</span><span style="color: #008080">43</span> 
<span style="color: #008080">44</span> <span style="color: #0000ff">try</span><span style="color: #000000">:
</span><span style="color: #008080">45</span>     <span style="color: #008000">#</span><span style="color: #008000"> Conn = httplib.HTTPConnection(HOST, PORT, STRICT, TIMEOUT, SOURCEURL)</span>
<span style="color: #008080">46</span>     HttpClient =<span style="color: #000000"> httplib.HTTPConnection(HOST)
</span><span style="color: #008080">47</span>     HttpClient.request(<span style="color: #800000">'</span><span style="color: #800000">POST</span><span style="color: #800000">'</span><span style="color: #000000">, POSTURL, TestDATA, HEADERS)
</span><span style="color: #008080">48</span> 
<span style="color: #008080">49</span>     response =<span style="color: #000000"> HttpClient.getresponse()
</span><span style="color: #008080">50</span>     <span style="color: #0000ff">print</span><span style="color: #000000"> response.status
</span><span style="color: #008080">51</span>     <span style="color: #0000ff">print</span><span style="color: #000000"> response.reason
</span><span style="color: #008080">52</span>     <span style="color: #0000ff">print</span><span style="color: #000000"> response.read()
</span><span style="color: #008080">53</span>     <span style="color: #0000ff">print</span><span style="color: #000000"> response.getheaders()
</span><span style="color: #008080">54</span> <span style="color: #0000ff">except</span><span style="color: #000000"> Exception, e:
</span><span style="color: #008080">55</span>     <span style="color: #0000ff">print</span><span style="color: #000000"> e
</span><span style="color: #008080">56</span> <span style="color: #0000ff">finally</span><span style="color: #000000">:
</span><span style="color: #008080">57</span>     <span style="color: #0000ff">if</span><span style="color: #000000"> HttpClient:
</span><span style="color: #008080">58</span>         HttpClient.close()

 

以上是Python之POST登录测试的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Python的科学计算中如何使用阵列?Python的科学计算中如何使用阵列?Apr 25, 2025 am 12:28 AM

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

您如何处理同一系统上的不同Python版本?您如何处理同一系统上的不同Python版本?Apr 25, 2025 am 12:24 AM

你可以通过使用pyenv、venv和Anaconda来管理不同的Python版本。1)使用pyenv管理多个Python版本:安装pyenv,设置全局和本地版本。2)使用venv创建虚拟环境以隔离项目依赖。3)使用Anaconda管理数据科学项目中的Python版本。4)保留系统Python用于系统级任务。通过这些工具和策略,你可以有效地管理不同版本的Python,确保项目顺利运行。

与标准Python阵列相比,使用Numpy数组的一些优点是什么?与标准Python阵列相比,使用Numpy数组的一些优点是什么?Apr 25, 2025 am 12:21 AM

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基于基于duetoc的iMplation,2)2)他们的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函数函数函数函数构成和稳定性构成和稳定性的操作,制造

阵列的同质性质如何影响性能?阵列的同质性质如何影响性能?Apr 25, 2025 am 12:13 AM

数组的同质性对性能的影响是双重的:1)同质性允许编译器优化内存访问,提高性能;2)但限制了类型多样性,可能导致效率低下。总之,选择合适的数据结构至关重要。

编写可执行python脚本的最佳实践是什么?编写可执行python脚本的最佳实践是什么?Apr 25, 2025 am 12:11 AM

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

Numpy数组与使用数组模块创建的数组有何不同?Numpy数组与使用数组模块创建的数组有何不同?Apr 24, 2025 pm 03:53 PM

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,内存效率段

Numpy数组的使用与使用Python中的数组模块阵列相比如何?Numpy数组的使用与使用Python中的数组模块阵列相比如何?Apr 24, 2025 pm 03:49 PM

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

CTYPES模块与Python中的数组有何关系?CTYPES模块与Python中的数组有何关系?Apr 24, 2025 pm 03:45 PM

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。