我想通过 C 调用 Web 服务。我无法使用任何现有的库来实现相同目的。因此,我在 Tomcat 端口 8080 上打开套接字(某些应用程序正在 Tomcat 上运行)。
我正在通过套接字向 tomcat 发送一个 HTTP POST 请求,其中包含 SOAP 消息。我能够调用 Web 服务,但无法接收作为 SOAP 发送的数据。这是一个带有 SOAP 的 HTTP 请求,我通过套接字将其发送到 Tomcat
POST http://hostip.com:8080/APP/WebServiceName HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://www.companyname.com/webservices"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 192.168.50.151
Content-Length: length
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.company.com/webservices">
<soapenv:Header/>
<soapenv:Body>
<web:DataRequest>
<web:Scope>iOWNjuYroYC6HB</web:Scope>
<web:Source>
<web:ChildLine>
<web:ID>RnUNjuYroYC6HB</web:ID>
<web:Matrix>15</web:Matrix>
</web:ChildLine>
</web:Source>
<web:UserVariables>
<web:Variable>
<web:Key>Rule</web:Key>
<web:Value>Working</web:Value>
</web:Variable>
<web:Variable>
<web:Key>543</web:Key>
<web:Value>96</web:Value>
</web:Variable>
</web:UserVariables>
</web:DataRequest>
</soapenv:Body>
</soapenv:Envelope>
最佳答案
我不确定我是否完全理解你的意思。 但是...如果您一对一地发送此示例消息,它将是不正确的。 您需要将“Content-Length: length”部分中的“length”文本更改为带有数字的实际长度。我认为你更改为实际长度(以字节为单位,没有 header 长度),那么结果可能会更好。
关于c - C 套接字中通过 HTTP 的 SOAP 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22840295/