代码之家  ›  专栏  ›  技术社区  ›  Vishal Raghavan

Jmeter-使用参数发送请求,但不使用body

  •  0
  • Vishal Raghavan  · 技术社区  · 6 年前

    我正在对我的网站API进行负载测试。我尝试向网站发送一个登录请求,该请求需要用户名和密码。我最初设置了http头管理器、cookie管理器和http请求。

    我在参数中输入name(用户名、密码)和value参数(分别是vis和new),然后点击start,测试成功完成。另一方面,如果我键入键值对作为字典 {"username":"vis","password":"new"} 在body选项卡中,然后再次运行,然后请求标头具有post数据(从查看结果树中可以看到),但我的服务器无法识别post数据。它只是返回错误,就好像没有发送post数据一样。

    Content-Type application/json

    一些错误屏幕打印: 标题设置 Header setting

    Request parameters

    在树中查看结果-请求标头:

    Connection: keep-alive
    Content-Type: application/json
    Content-Length: 35
    Host: url.com
    User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_191)
    

    请求机构:

    POST https://url.com/accounts/login.json
    
    POST data:
    {"username":"vis","password":"new"}
    
    [no cookies]
    

    所以,当我在“参数”选项卡下发送请求时,请求有效,但在使用“身体数据”选项卡时,请求无效。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Dmitri T    6 年前

    您无法登录,因为您的应用程序不支持您提供凭据的方式。

    如果Python请求对您的应用程序运行良好,只需使用JMeter的 HTTP(S) Test Script Recorder

    1. 准备JMeter进行记录。最快的方法是使用J Meter Templates 特色

      • 从JMeter的主菜单中选择 File -> Templates -> Recording

        enter image description here

      • enter image description here

    2. 将Python脚本修改为 use JMeter as the proxy :

      import requests
      
      jmeter = {
        'http': 'http://localhost:8888',
        'https' : 'http://localhost:8888'
      }
      
      requests.post("https://url.com/accounts/login.json",data={"username":"vis","password":"new"}, proxies=jmeter)
      
    3. 执行Python脚本

    4. Recording Controller . 这将是您测试时应使用的请求:

      enter image description here