postman可以请求web service接口吗,Transport level information does not match with SOAP Message namespace URI

一、背景

postman可以请求web service接口吗,一定要安装soap-UI软件吗?
不需要,请求web service本质也是HTTP请求,可以用postman请求web service

二、如何用 POSTMAN 请求web service接口

不难,要做到:

  1. 要知道请求的URL是什么
  2. 要用POST

因为有request body你肯定不能用GET,我没试过PUT之类的是否可以,但是这个web service这么古老,诞生在之用GET/POST的年代怎么会想到用PUT呢,老实用POST即可

  1. request body要有参数

就算是实际请求的接口没有参数,总是需要包装成soap消息的,即xml的请求参数丢到request body里

  1. 要设置正确的Content-Type

header里只要设置一个header即Content-Type即可

三、如何设置正确的Content-Type

根据web service的版本不同,设置的Content-Type有小差异

设置不正确,会出现 soapenv:VersionMismatch 和 Transport level information does not match with SOAP Message namespace URI 的错误提示

是什么版本关键看请求参数的声明:
<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/”
<soap:Envelope xmlns:soap=“http://www.w3.org/2003/05/soap-envelope”

SOAP 1.1 : http://schemas.xmlsoap.org/soap/envelope/
SOAP 1.2 : http://www.w3.org/2003/05/soap-envelope

1.1的content-type要用 text/xml,也可以加上编码:text/xml; charset=utf-8
1.2用:application/soap+xml 或也可以加上编码:application/soap+xml; charset=utf-8

如果设置了错误的Content-Type,比如1.2的设置了text/xml,则报错,明显提示了Version mis match

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:VersionMismatch</faultcode>
            <faultstring>Transport level information does not match with SOAP Message namespace URI</faultstring>
            <detail></detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

猜你喜欢

转载自blog.csdn.net/w8y56f/article/details/131342702