首页 > 解决方案 > 从 Linux 发送 SOAP 请求时出现意外字符

问题描述

我试图发送一个 SOAP 请求。

curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: " --data-binary file.xml  https://endpoint.com

我将 xml 文件中的请求正文指定为 -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dse="http://brandmaker.com/webservices/dse/v2/">
 <soapenv:Header/>
  <soapenv:Body>
    <dse:findById>
      <id>1405</id>
    </dse:findById>
  </soapenv:Body>
</soapenv:Envelope>

当我从 Mac 发送请求时,此文件工作正常。但是,当我将文件从 Mac 复制到 Linux 并尝试相同的命令时,我遇到了无效字符问题 -

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body> . 
     <soap:Fault>
        <faultcode>soap:Client</faultcode>
        <faultstring>Error reading XMLStreamReader: Unexpected character 'f' (code 102) in prolog; expected '&lt;' at [row,col {unknown-source}]: [1,1]</faultstring>
     </soap:Fault>
   </soap:Body>
</soap:Envelope>%  

我尝试转义内容,但仍然遇到相同的错误-

&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:dse=&quot;http://brandmaker.com/webservices/dse/v2/&quot;&gt;
   &lt;soapenv:Header/&gt;
   &lt;soapenv:Body&gt;
     &lt;dse:findById&gt;
       &lt;id&gt;1405&lt;/id&gt;
     &lt;/dse:findById&gt;
   &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;

谁能帮我?从 Linux 发送请求时,我应该如何编码 xml 请求正文?

标签: xmlcurlsoap

解决方案


很可能它正在发送包含文字 text 的 POST 数据file.xml

尝试:

curl -X POST \
-H "Content-Type: text/xml" \
-H "SOAPAction: " \
--data-binary @file.xml \
https://endpoint.com

对于 Linux,文档--data-binary内容如下:

--data-binary <data>
    (HTTP) This posts data exactly as specified with no extra processing whatsoever.

    If you start the data with the letter @, the rest should be a filename.
    Data is posted in a similar manner as --data-ascii does, except  that  newlines
    and carriage returns are preserved and conversions are never done.

    If this option is used several times, the ones following the first will
    append data as described in -d, --data.

推荐阅读