我们知道webservice其实际上还是http请求,所以理论上是可以用curl调用的。

其实调用很简单,webservice的headers 是 Content-Type: text/xml;charset=UTF-8。直接加上header,传递xml格式的消息就可以。完整调用格式如下:

curl -v -H "Content-Type: text/xml;charset=UTF-8" -d "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:husolar=\"http://husolar.com\"> <soapenv:Header/> <soapenv:Body> <husolar:test> <reqContent>AAAAA</reqContent></husolar:test></soapenv:Body></soapenv:Envelope>" -X POST  http://localhost:8080/husolar/test?wsdl

需要注意的是,xml格式中的引号需要转义。请求消息内容可以放入到文件中,采用

-d "@test.xml"  的方式可以更加简洁,以及便于修改。完整格式如下:

curl -v -H "Content-Type: text/xml;charset=UTF-8" -d "@D://test.xml" -X POST  http://localhost:8080/husolar/test?wsdl

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐