Related Articles
压侧工具 ngrinder 学习(安装)
2016 年 12 月 8 日
ss服务搭建 翻墙
2016 年 6 月 14 日
linux下压力测试软件siege的安装与使用详解
2016 年 5 月 24 日
# -*- coding:utf-8 -*- # A simple example using the HTTP plugin that shows the retrieval of a # single page via HTTP. # # This script is automatically generated by ngrinder. # # @author admin from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest from net.grinder.plugin.http import HTTPPluginControl from HTTPClient import NVPair #导入对JSON格式返回值的处理函数 from org.json import JSONObject import sys reload(sys) sys.setdefaultencoding('utf-8') control = HTTPPluginControl.getConnectionDefaults() # if you don't want that HTTPRequest follows the redirection, please modify the following option 0. # control.followRedirects = 1 # if you want to increase the timeout, please modify the following option. control.timeout = 6000 test1 = Test(1, "api.vd.cn") request1 = HTTPRequest() # Make any method call on request1 increase TPS test1.record(request1) class TestRunner: # initlialize a thread def __init__(self): grinder.statistics.delayReports=True pass # test method def __call__(self): headers = [ NVPair("Content-Type","application/json") ] json_data='{"is_card_photo":"1","wid":"200168668","BaseAppType":"android","BaseAppVersion":"4.4.0","SystemVersion":"4.4.2","shop_id":"11433415","_sign_":"DDFDDA37A35F2CF28591FC6D18245779","_token_":"53c571f37a7e2fe64cc4d24200fdd8ca","_wid_":"200168668","appIdentifier":"com.hs.yjseller"}' #submitdata = [NVPair("a","1"),NVPair("b","2"),NVPair("c","3")] result = request1.POST(" ip/user/getuseraddressall", json_data, headers) # You get the message body using the getText() method. # if result.getText().find("HELLO WORLD") != -1 : # grinder.statistics.forLastTest.success = 1 # else : # grinder.statistics.forLastTest.success = 0 # if you want to print out log.. Don't use print keyword. Instead, use following. #grinder.logger.info(result.getText()) if result.getStatusCode() == 200 : grinder.statistics.forLastTest.success = 1 elif result.getStatusCode() in (301, 302) : grinder.logger.warn("Warning. The response may not be correct. The response code was %d." % result.getStatusCode()) grinder.statistics.forLastTest.success = 1 else : grinder.statistics.forLastTest.success = 1