本文来介绍在
Postman
中如何使用 WebService 请求,更多相关的知识,可访问
Postman 的 WebService 模块
。
webService
Web Service 是一个拥有以下特性的应用程序:
-
平台独立的
-
低耦合的
-
自包含的
-
基于可编程的 web 的
使用 Web Service 技术,可以让你在不同机器的数据传输上,更加地方便,因为你并不需要借助一些其他的配件来协助操作。并且,你这些不同的机器,并不用担心使用的语言不同,或者协议不同,这些都不需要你去考虑。
Web Service 是一个很方便的网络模块,他也可以去执行业务。他也比较容易部署,因为 Web Service 基于以前就存在的一些规则或者技术,所以大大降低了部署成本~
webService VS webApi
-
webapi 用的是 http 协议,webservice 用的是
soap
协议
-
webapi 无状态,相对 webservice 更轻量级。webapi 支持如 get,post 等
http
操作
定义 webService 接口
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.util.ArrayList;
@WebService
public interface UserService {
@WebMethod
String getName(@WebParam(name = "req1") String req1, @WebParam(name = "req2") String req2);
@WebMethod
User getUser(@WebParam(name = "userId") String userId);
@WebMethod
User getUserObj(@WebParam(name = "user") UserReq req);
@WebMethod
ArrayList<User> getAlLUser();
设置
需要先设置这两个地方
-
Headers 需要设置 Content-Type 为 text/xml;charset=utf-8
-
Body 选择 raw XML (text/xml)
设置 Content-Type
raw XML
请求参数
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://service.webservicedemo.owater.com/">
<soapenv:Body>
<ws:getName>
<userId>Owater</userId>
</ws:getName>
</soapenv:Body>
</soapenv:Envelope>
响应
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://service.webservicedemo.owater.com/">
<soapenv:Body>
<ws:getName>
<userId>Owater</userId>
</ws:getName>
</soapenv:Body>
</soapenv:Envelope>
发送
发送
Apifox 调试 webService
Apifox
也可以做同样的事,而且优点更多:
Apifox 是一体化 API 协作平台,可以实现 API 文档、API 调试、
API Mock
、 API 自动化测试,是更先进的 API 设计/开发/测试工具。
使用 Apifox ,你可以在一个统一的平台上设计、调试、测试以及协作你的 API,消除了在不同工具之间切换和数据不一致的问题, 简化了 API 工作流,并确保了前端、后端和测试人员之间的高效协作。
设置
设置 raw
发送
发送
Apifox 调试 WebService 接比 Postman 更加简便,快去试试吧,点击免费使用!
知识扩展
了解更多 Postman 相关使用技巧:
postman