打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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个头部参数

  • Content-Type: text/xml; charset=utf-8
  • SOAPAction: “http://WebXml.com.cn/getDatabaseInfo“

添加SOAP 请求参数

  • url地址 :http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx
  • Soap version : 1_1  (默认是1_2)
  • 勾选Treat selected attachment as response
  • SOAP Envelope 添加请求body内容

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

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 请求参数

  • url地址 :http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx
  • Soap version : 1_2  (默认是1_2)
  • 勾选Treat selected attachment as response
  • SOAP Envelope 添加请求body内容(注意是接口文档上1.2的body内容)

查看运行结果

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 ,不带参数可以不用管

结果返回


2021年第六期《python接口自动化+测试开发》课程,1月9号开学(火热报名中!)

1月9-4月1820:30-22:30

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
实时股票数据接口
PHP5 扩展SOAP 调用 webservice
WebService CXF学习(进阶篇3):对象传递
[018] Android开发之WebService介绍
JAVA 调用Web Service的方法 - 轻松 的博客 - 博客园
android中调用webservice
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服