四时宝库

程序员的知识宝库

postman-SOAP 请求(postman调用soap)

除了 REST、GraphQL和WebSocket请求之外,Postman 还可以使用 SOAP(一种与平台无关的消息传递协议规范)进行 HTTP 调用。

以下步骤显示了如何在 Postman 中发出 SOAP 请求。

输入您的 SOAP 端点

在 Postman 中打开一个新的请求选项卡,并在地址字段中输入您的 SOAP 端点 URL。

从请求方法下拉列表中选择POST 。

例如,使用以下端点 URL

https://www.dataaccess.com/webservicesserver/NumberConversion.wso

此 SOAP 端点将数值更改为其文本等效项,例如将值“500”更改为“五百”。

添加正文数据

在Body选项卡中,选择raw并从下拉列表中选择XML 。

在文本输入区域中输入您的 XML。

如果要测试上一节中使用的数字转换 SOAP API,请在文本输入区域输入以下 XML:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
<ubiNum>500</ubiNum>
</NumberToWords>
</soap:Body>
</soap:Envelope>

您的请求正文必须包含端点要求的 SOAP Envelope、Header和Body标签,以及任何命名空间。数据需要包含操作的名称,以及您需要发布到服务的任何值。

设置您的请求标头

当您选择 XML 正文类型时,Postman 会自动添加application/xml. 但根据您的服务提供商,您可能需要text/xml一些 SOAP 请求。检查您的 SOAP 服务以确定哪个标头是合适的。如果您需要text/xml标头,则需要覆盖 Postman 添加的默认设置。

如果您跟随数字转换 SOAP API 示例,您需要将内容类型标头更改为text/xml.

  1. 打开请求标头。如果自动生成的标题被隐藏,请选择通知以显示它们。
  2. 取消选择Content-Type邮递员自动添加的标题。
  3. Content-Type在Key字段和Valuetext/xml字段中添加一个新行。
  4. SOAPAction在Key字段和Value"#MethodName"字段中为标题添加新行 。(引号是必需的。)如果没有此标头,服务将返回 500。

发送您的请求

选择发送以调用 SOAP 服务。如果您的呼叫成功,您将在 Postman 的下方选项卡中看到响应。

异常一: no SOAPAction header!

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
<faultstring>no SOAPAction header!</faultstring>
<detail>
<ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">iZ3ppe8zx62ky3Z</ns2:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>


解决:

在Header里添加:

SOAPAction application/soap+xml;charset=utf-8

异常二:net.sf.json.JSONException: A JSONArray text must start with '[' at character 0 of

解决:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://xml.apache.org/axis/">
<soapenv:Body>
<uploadAlarmMessage>
<cid>[ {'idxx': 'xxxx',
'alarmxxx':'xxxx',
'time':'2012-10-22 10:58:06'}
]</cid>
</uploadAlarmMessage>
</soapenv:Body>
</soapenv:Envelope>

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言