• jmeter4.0执行HTTP请求报400,jmeter5.1运行正常解决方法


    最近经常接触有测试人员脚本在jmeter4.0运行失败,返回Response code: 400,HTTP返回400,官方解释是"Bad Request 客户端请求的语法错误,服务器无法理解",在jmeter5.1执行正常,这里本文记录下解决方法

    一、jmeter4.0执行结果如下
    1. 请求如下
    [外链图片转存失败(img-E2u0PrvU-1569117698158)(https://s1.51cto.com/images/blog/201909/16/6696cd635105ecc54668bd6343657231.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    2. 响应数据如下
    [外链图片转存失败(img-4iBEQKIA-1569117698160)(https://s1.51cto.com/images/blog/201909/16/0ca1a86ccc4210d1c00326eae4d10457.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]

    二、jmeter5.1执行结果如下
    1. 请求Request Body
    [外链图片转存失败(img-HaxliON1-1569117698162)(https://s1.51cto.com/images/blog/201909/16/32423c8c21c263d10b861ea32fcb2d7a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    2. 请求Request Headers
    [外链图片转存失败(img-B3tqDA8p-1569117698164)(https://s1.51cto.com/images/blog/201909/16/ff22b5fa7b388a581521032bec3769e9.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    3. 响应数据Response Body
    [外链图片转存失败(img-lgSo08Po-1569117698165)(https://s1.51cto.com/images/blog/201909/16/701de5466a42c6b21896335cfdf40baf.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    4. 响应数据Response headers
    [外链图片转存失败(img-CjKgdQV3-1569117698167)(https://s1.51cto.com/images/blog/201909/16/3edb1fce24df9a562bde313769bc72bf.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    5. 响应数据Response headers
    [外链图片转存失败(img-0DG14E4Y-1569117698169)(https://s1.51cto.com/images/blog/201909/16/3edb1fce24df9a562bde313769bc72bf.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]

    三、问题分析
    1. 脚本如下,看脚本可以得出脚本没有申明HTTP信息头管理器,所以系统调用的默认请求表头
    [外链图片转存失败(img-uNxVUgSH-1569117698170)(https://s1.51cto.com/images/blog/201909/16/5dcc09180cc5fc3a02b33519cbfcb0e0.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    2. 经过对比jmeter4.0和jmeter5.1请求表头差异,可以看出他们的请求默认表头不一样,Jmeter5.1 HTTP接口 默认Content-Type类型为text/plain; Jmeter4.0 HTTP接口默认Content-Type类型为application/x-www-form-urlencoded,由于性能测试脚本HTTP接口表头类型就是text/plain,所以执行成功
    [外链图片转存失败(img-BIj7rphO-1569117698171)(https://s1.51cto.com/images/blog/201909/16/91d87a0da7396581693e4c6c967710ea.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    3. 所以我们只需要在脚本中自己添加一个信息头管理器,然后申明为text/plain就行,右键测试计划》添加》配置元件》HTTP信息头管理器
    [外链图片转存失败(img-3syw6BIS-1569117698172)(https://s1.51cto.com/images/blog/201909/16/6b6fbadfeb7c49fcdd66203e04513d77.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    4. 在信息头管理器,添加Content-Type=text/plain
    [外链图片转存失败(img-BS6eouMR-1569117698173)(https://s1.51cto.com/images/blog/201909/16/b934bc994a31f6e61d9e9d6638cfe1f5.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]
    5. 点击执行按钮,执行成功
    [外链图片转存失败(img-VzKUTNBR-1569117698174)(https://s1.51cto.com/images/blog/201909/16/89d584da9fdcb36f09b9e2115512c917.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]


    如果文章对你有帮助,可以在右下角点击关注功能,欢迎转发、拍砖,本人会持续推出与测试有关的文章,与大家分享测试技术,每一篇原创文章都是用心编写,杜绝抄袭复制,微信公众号与本平台文章同步,方便大家查阅


    QQ技术交流群:加群请输入验证信息 博客园
                  [外链图片转存失败(img-RjtRTVOl-1569117698175)(https://s1.51cto.com/images/blog/201908/27/4691ba234a0ba147d763ecf517dec03e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]


    微信二维码关注公众号:

    [外链图片转存失败(img-urHjwKjY-1569117698176)(https://s1.51cto.com/images/blog/201909/09/a5009e24d0a0b0863b3f822bcffbbc27.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]


    关注之后,回复资源下载,即可获取本人共享的各种资源下载地址

    [外链图片转存失败(img-1LRqxDzs-1569117698177)(https://s1.51cto.com/images/blog/201908/06/2e62f8806e1dc1c391c4332ac7fd70b1.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)]

  • 相关阅读:
    我们的回忆

    出差
    恍惚
    七夕
    K8S命令(一)——Node相关
    K8S命令(二)——查询相关
    [转载]为什么你应该(从现在开始就)写博客
    替代JDK日期的开源项目:jodatime
    使用getElementById获取xml中的指定元素
  • 原文地址:https://www.cnblogs.com/Jmeter-Automation/p/12730655.html
Copyright © 2020-2023  润新知