【问题标题】:What's the difference between curling the data via cat and via data parameter?通过 cat 和通过 data 参数卷曲数据有什么区别?
【发布时间】:2016-06-23 21:18:22
【问题描述】:

如果我通过curl SOAP 服务器:

curl 'http://the-soap-server' -H 'Content-Type: text/xml; charset=utf-8' \
-H 'SOAPAction: http://tempuri.org/Action' -X POST \
--data '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
    <tem:Booking>
    ...
    </soapenv:Body>
</soapenv:Envelope>'

我收到来自soap 服务器的错误响应。然而奇怪的是,如果我将该请求存储在一个文件中并通过以下方式发出相同的请求:

cat stored.xml | curl 'http://the-soap-server' -H 'Content-Type: text/xml; charset=utf-8' \
-H 'SOAPAction: http://tempuri.org/Action' -X POST \
--data @-

它突然起作用了。这些 curl 请求有何不同?

【问题讨论】:

    标签: curl soap http-post httprequest newline


    【解决方案1】:

    换行。

    我使用 php 代理 http 服务器来查看收到的正确请求并比较了差异。

    第一种方法保留换行符,另一种方法删除它们。而且这个特定的肥皂服务器不喜欢换行符。

    所以要通过内联数据获取 curl,必须:

    curl 'http://the-soap-server' -H 'Content-Type: text/xml; charset=utf-8' \
    -H 'SOAPAction: http://tempuri.org/Action' -X POST \
    --data '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header/><soapenv:Body><tem:Booking>...</soapenv:Body></soapenv:Envelope>'
    

    【讨论】:

      猜你喜欢
      • 2015-08-27
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 2017-06-04
      相关资源
      最近更新 更多