我想使用VBA Excel发出SOAP请求VBA请求
Public Sub httpclient()
Dim Req As Object
Dim sEnv As String
Dim Resp As New MSXML2.DOMDocument60
Set Req = CreateObject("MSXML2.XMLHTTP")
Set Resp = CreateObject("MSXML2.DOMDocument.6.0")
Req.Open "GET", "https://api.etadirect.com/soap/capacity/?wsdl", False
sEnv = sEnv & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope"">"
sEnv = sEnv & " <soapenv:Header/>"
sEnv = sEnv & " <soapenv:Body>"
sEnv = sEnv & " <Request>"
sEnv = sEnv & " <now>2019-07-22</now>"
sEnv = sEnv & " <login>string</login>"
sEnv = sEnv & " <company>string</company>"
sEnv = sEnv & " <auth_string>string</auth_string>"
sEnv = sEnv & " </Request>"
sEnv = sEnv & " </soapenv:Body>"
sEnv = sEnv & "</soapenv:Envelope>"
' Send SOAP Request
Req.Send (sEnv)
Debug.Print Req.responseText
End Sub
SOAP UI请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toa:capacity">
<soapenv:Header/>
<soapenv:Body>
<urn:get_quota_data>
<user>
<now>2019-07-22</now>
<login>string</login>
<company>string</company>
<auth_string>string</auth_string>
</user>
</urn:get_quota_data>
</soapenv:Body>
</soapenv:Envelope>
我期望获得下面的结果,而不是我获得了大量的xml标记。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Bad request format - Mandatory parameter is absent: 'date'</faultstring>
<detail>
<errorCode>100</errorCode>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAPUI返回强制参数是缺席的,因为我写的请求只是为了验证。在相同的vba中,我没有收到此消息。问题是我在VBA代码中做错了什么。你能帮助我吗?最好的问候,
1条答案
按热度按时间zfycwa2u1#
我遇到的主要问题是SOAP标记soapenv(泛型)和sear(特定于服务)的正确声明。这个VBA函数可以获取任意数量的节点,尽管在我的例子中,我只对Web服务中数千个可用对象中的一个感兴趣。
出错时后藤ErrHandler将xmlhttp变小为新MSXML2.XMLHTTP60将URL变小为字符串变小为字符串变小为字符串变小为字符串结果
ErrHandler:result = Err.说明恢复清理恢复'仅调试清理:'返回结果GetWebServiceData =结果结束函数