使用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

 

posted @ 2015-12-01 16:43  我不写博客  阅读(6821)  评论(0编辑  收藏  举报