Linux/Unix系統默認安裝了curl,我們可以使用curl命令行方式測試接口
步驟1:
創建一個Soap Envelope,另存為比如request.xml,文件內容為該soap接口消息體,比如如下
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.tudb.com/"> <soapenv:Header/> <soapenv:Body> <web:execute> <!--Optional:--> <arg0>XX</arg0> </web:execute> </soapenv:Body> </soapenv:Envelope>
步驟2:
構造消息頭,放到-H/ --header 參數后面,一個header加一個參數,可以添加多個header。
比如:
--header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:XX"
攔截一個正常的消息,獲得消息的Header信息,然后再curl參數中構造,比如某個消息有如下header信息,我們可以都加上進行更精確的模擬。
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 490
Host: 10.191.21.141:28080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
步驟3:
執行命令:
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:" --data @request.xml http://www.example.com/XX
其他一些常用參數:
-O: 保存到文件
-I:只展示消息頭
等等
具體可以curl -h 或者 man curl