使用Curl進行soap接口測試


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM