【问题标题】:Linux, Curl, send a -X POST without xml fileLinux,Curl,发送没有 xml 文件的 -X POST
【发布时间】:2018-11-15 09:16:10
【问题描述】:

我在 Linux 中有一个小 sh 脚本,用于带有 curl 的 -X POST:

curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" --data @\u\ManInTheMiddle.xml  | grep -o 'true\|false'

这很好,但我必须先编写 ManInTheMiddle.xml,第二步我可以发送 curl 命令。

ManInTheMiddle.xml

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <InsertPruefResultatFromXMLFile xmlns="http://tempuri.org/">
            <FilePath>\\serverip\script.xml</FilePath>
        </InsertPruefResultatFromXMLFile>
    </Body>
</Envelope>

有没有办法在没有 xml 文件的情况下做到这一点?直接发送“\serverip\script.xml”

喜欢:

curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" --d "\\serverip\script.xml"  | grep -o 'true\|false'

有什么想法吗?

编辑1: 我只想用 ManInTheMiddle.xml 处理中间步骤,以便服务器直接获取到导入文件 (\serverip\script.xml) 的链接。

编辑2: 使用 python 它可以工作:

url = "http://serverip/WebServices/WebServiceSQLTestresult.svc?wsdl"

import suds
import suds.client
client = suds.client.Client(url)
result = client.service.InsertPruefResultatFromXMLFile("\\\\serverip\script.xml")

谢谢...

【问题讨论】:

  • 您询问是否可以直接发送\\serverip\script.xml,而不是发送请求以要求服务使用\\serverip\script.xml 语法从Windows 共享文件夹加载该文件。但我们对http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl 服务一无所知,因此无法回答。您需要去与编写此 Web 服务的人交谈并询问他们 - 我们不知道该服务是如何工作的。
  • 好的,所以我对 curl 有了更多的了解...谢谢...我想如果服务器的文件或链接相同。

标签: xml linux curl


【解决方案1】:

在文件名路径前使用@:

curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" -d @"\\serverip\script.xml"  | grep -o 'true\|false'

【讨论】:

    【解决方案2】:

    $() 救援,替换

    --data @\u\ManInTheMiddle.xml
    

    --data-raw "$(curl --silent \\serverip\script.xml)"
    

    类似

    curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" --data-raw "$(curl --silent \\serverip\script.xml)"  | grep -o 'true\|false'
    

    请注意 $() 的可移植性如何,例如,它肯定不能在 microsoft 的 cmd.exe 上运行,但至少它可以在 bash 上运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 2018-06-13
      • 1970-01-01
      • 2010-09-19
      • 1970-01-01
      • 2022-08-14
      • 2015-03-19
      相关资源
      最近更新 更多