前言
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-8
和 SOAPAction
這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 ,不帶參數可以不用管
結果返回