c - C 套接字中通过 HTTP 的 SOAP 消息

标签 c sockets http soap httprequest

我想通过 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/

相关文章:

c - Openssl 的堆内存使用情况

c - C 中同一个 if 语句中的多个条件

javascript - 如何使用tcp套接字将图像从[python客户端]发送到[node.js服务器]?

java - Java 中是否有任何用于原始套接字的 API,示例也会有所帮助

c++ - 使用接受的连接作为套接字 (cpp-netlib)

从 Windows 到 Linux 的 HTTP 协商失败

c - 带状态机的正则表达式

c - 用什么代替模数?

Linux 上的 PHP 套接字 - 在通过命令退出 php 之后/当 php 退出时立即释放 tcp 端口?

java - 从 URL 读取奇怪的 byte[] 行为