关于什么是web services,可以到W3C中查看详细的信息,本文章主要介绍使用Jmeter怎么来做web services的接口测试,首先它也是基于HTTP协议的,我们实现电话号码归属地的查询,首先来看请求信息和响应信息,见如下:
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/getMobileCodeInfo"
<?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>
<getMobileCodeInfo xmlns="http://WebXml.com.cn/">
<mobileCode>string</mobileCode>
<userID>string</userID>
</getMobileCodeInfo>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
<getMobileCodeInfoResult>string</getMobileCodeInfoResult>
</getMobileCodeInfoResponse>
</soap:Body>
</soap:Envelope>
在如上的信息中,可以得知如下的信息:
请求地址:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx
请求方法:POST
Content-Type:text/xml;charset=utf-8
请求参数:mobileCode,该参数不能为空,userID,该参数可以为空
请求成功后,响应的响应数据显示该电话号码它是在哪个归属地,下面使用Jmeter实现这部分。
首先在Jmeter创建线程组,见创建后的目录结构截图:
见HTTP信息头管理器截图:
见具体的接口用例请求参数截图:
点击run后,见执行的结果截图:
在如上的截图中,可以看到客户端发送请求后,服务端响应回复的数据,在这里特别注意HTTP的信息头管理器,它的Content-Type是text/xml,还有就是请求参数部分。
其它接口测试涉及的知识点,会逐步的介绍,谢谢!