• jmeter压测学习47-发soap请求测试webservice接口


    前言

    jmeter3 的版本可以新建一个SOAP/XML-RPC Request 的请求,直接测试webservice的接口。
    jmeter5.1.1 版本已经去掉了自带的SOAP/XML-RPC Request,需在插件管理安装 Custom SOAP Sampler 插件

    Custom SOAP Sampler 插件

    选项-Plugins Manager - Available Plugins - 搜索 soap 勾选 Custom SOAP Sampler 插件安装

    webservice接口

    通过浏览器访问也可以看到对应的方法和请求参数http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx

    测试 getDatabaseInfo 接口不用带参数

    调用后返回

    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">
    <string>全部 数据 265903</string>
    <string>安徽 安庆 658</string>
    <string>安徽 蚌埠 456</string>
    <string>安徽 亳州 489</string>
    ......
    </ArrayOfString>
    

    jmeter 发SOAP 1.1

    先看 SOAP 1.1的版本请求示例

    # 作者-上海悠悠 QQ交流群:717225969
    # blog地址 https://www.cnblogs.com/yoyoketang/
    POST /WebServices/MobileCodeWS.asmx HTTP/1.1
    Host: ws.webxml.com.cn
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://WebXml.com.cn/getDatabaseInfo"
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <getDatabaseInfo xmlns="http://WebXml.com.cn/" />
      </soap:Body>
    </soap:Envelope>
    

    SOAP 1.1的版本需在头部声明 Content-Type: text/xml; charset=utf-8SOAPAction 这2个参数.
    SOAPAction 对应的值,可以在接口文档上查看到 SOAPAction: "http://WebXml.com.cn/getDatabaseInfo"

    jmeter上添加-取样器-Custom SOAP Sampler

    添加 HTTP信息头管理器,SOPA 1.1版本需声明2个头部参数

    添加SOAP 请求参数

    查看请求结果(这里结果有中文会显示乱码)

    jmeter 发SOAP 1.2

    接下来再看下jmeter 发 SOAP 1.2 请求,1.2和1.1的请求区别主要在头部,1.2版本的头部需声明

    Content-Type: application/soap+xml; charset=utf-8

    头部不需要SOAPAction 参数了,请求body的标签也有不一样是

    详细报文查看接口文档,以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

    # 作者-上海悠悠 QQ交流群:717225969
    # blog地址 https://www.cnblogs.com/yoyoketang/
    POST /WebServices/MobileCodeWS.asmx HTTP/1.1
    Host: ws.webxml.com.cn
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <getDatabaseInfo xmlns="http://WebXml.com.cn/" />
      </soap12:Body>
    </soap12:Envelope>
    

    jmeter上添加-取样器-Custom SOAP Sampler

    添加 HTTP信息头管理器,SOPA 1.2版本需声明

    • Content-Type: application/soap+xml; charset=utf-8

    添加SOAP 请求参数

    查看运行结果

    HTTP GET请求

    webservice的接口也可以直接发 http 协议的GET 请求,参考接口文档

    HTTP GET
    以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。
    # 作者-上海悠悠 QQ交流群:717225969
    # blog地址 https://www.cnblogs.com/yoyoketang/
    
    
    GET /WebServices/MobileCodeWS.asmx/getDatabaseInfo? HTTP/1.1
    Host: ws.webxml.com.cn
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <ArrayOfString xmlns="http://WebXml.com.cn/">
      <string>string</string>
      <string>string</string>
    </ArrayOfString>
    

    jmeter 上添加HTTP 取样器

    查看结果

    HTTP POST

    从接口文档上看,webservice 的接口也可以直接发 http 协议的 POST 请求

    HTTP POST
    以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。
    
    POST /WebServices/MobileCodeWS.asmx/getDatabaseInfo HTTP/1.1
    Host: ws.webxml.com.cn
    Content-Type: application/x-www-form-urlencoded
    Content-Length: length
    
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <ArrayOfString xmlns="http://WebXml.com.cn/">
      <string>string</string>
      <string>string</string>
    </ArrayOfString>
    

    jmeter 上添加HTTP 取样器, 如果带参数,可以头部声明 Content-Type: application/x-www-form-urlencoded ,不带参数可以不用管

    结果返回

  • 相关阅读:
    .Net常见笔试题
    冒泡排序算法 C#版
    Bundle捆绑压缩技术
    异步Ajax
    HtmlHelper总结
    HtmlHelper的扩展分页方法
    WCF
    程序猿值得看的几个技术网站(记录)
    Struts2和SpringMVC的区别
    nginx配置文件作用介绍
  • 原文地址:https://www.cnblogs.com/yoyoketang/p/14433287.html
Copyright © 2020-2023  润新知